From 5349d2aaa7657d64b3fe63eefaf41c3be6af2767 Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Tue, 1 Nov 2016 21:33:06 +1030 Subject: [PATCH 1/4] routing: fix hash of pubkeys. Found by PVS Studio. Reported-by: Jon Griffiths Signed-off-by: Rusty Russell --- daemon/routing.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/daemon/routing.c b/daemon/routing.c index 0b42f9039..4e8f72783 100644 --- a/daemon/routing.c +++ b/daemon/routing.c @@ -21,7 +21,7 @@ static const secp256k1_pubkey *keyof_node(const struct node *n) static size_t hash_key(const secp256k1_pubkey *key) { - return siphash24(siphash_seed(), key, sizeof(key)); + return siphash24(siphash_seed(), key, sizeof(*key)); } static bool node_eq(const struct node *n, const secp256k1_pubkey *key) From 024e6a585528424d9eb2da6d4ef940af84e44955 Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Tue, 1 Nov 2016 21:33:27 +1030 Subject: [PATCH 2/4] feechange: fix db updates. Found by PVS Studio. Reported-by: Jon Griffiths Signed-off-by: Rusty Russell --- daemon/feechange.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/daemon/feechange.c b/daemon/feechange.c index 2991c6c90..f01d6b0d0 100644 --- a/daemon/feechange.c +++ b/daemon/feechange.c @@ -135,7 +135,7 @@ void feechange_changestate(struct peer *peer, || newstate == SENT_FEECHANGE_COMMIT) db_new_feechange(peer, f); else if (newstate == RCVD_FEECHANGE_ACK_REVOCATION - || SENT_FEECHANGE_ACK_REVOCATION) + || newstate == SENT_FEECHANGE_ACK_REVOCATION) db_remove_feechange(peer, f, oldstate); else db_update_feechange_state(peer, f, oldstate); From feecabacce5b68c8c0e8b0abecd980474d558231 Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Fri, 4 Nov 2016 12:09:31 +1030 Subject: [PATCH 3/4] sphinx: fix marshalling/unmarshalling Unfortunately, this fix will break compatibility. Found by PVS Studio. Signed-off-by: Rusty Russell --- daemon/sphinx.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/daemon/sphinx.c b/daemon/sphinx.c index 725d0abde..c8f2eed99 100644 --- a/daemon/sphinx.c +++ b/daemon/sphinx.c @@ -110,9 +110,9 @@ static struct hoppayload *parse_hoppayload(const tal_t *ctx, u8 *src) int p = 0; struct hoppayload *result = talz(ctx, struct hoppayload); - read_buffer(&result->realm, src, sizeof(&result->realm), &p); - read_buffer(&result->amount, src, sizeof(&result->amount), &p); - read_buffer(&result->remainder, src, sizeof(&result->remainder), &p); + read_buffer(&result->realm, src, sizeof(result->realm), &p); + read_buffer(&result->amount, src, sizeof(result->amount), &p); + read_buffer(&result->remainder, src, sizeof(result->remainder), &p); return result; } @@ -120,9 +120,9 @@ static void serialize_hoppayload(u8 *dst, struct hoppayload *hp) { int p = 0; - write_buffer(dst, &hp->realm, sizeof(&hp->realm), &p); - write_buffer(dst, &hp->amount, sizeof(&hp->amount), &p); - write_buffer(dst, &hp->remainder, sizeof(&hp->remainder), &p); + write_buffer(dst, &hp->realm, sizeof(hp->realm), &p); + write_buffer(dst, &hp->amount, sizeof(hp->amount), &p); + write_buffer(dst, &hp->remainder, sizeof(hp->remainder), &p); } @@ -518,7 +518,7 @@ struct route_step *process_onionpacket( stream_decrypt(step->next->payload, msg->payload, sizeof(msg->payload), keys.pi); memcpy(&step->next->routinginfo, paddedheader + 2 * SECURITY_PARAMETER, ROUTING_INFO_SIZE); - if (memeqzero(step->next->mac, sizeof(&step->next->mac))) { + if (memeqzero(step->next->mac, sizeof(step->next->mac))) { step->nextcase = ONION_END; } else { step->nextcase = ONION_FORWARD; From 25bb0f52482e5d805a1874859de7d75b4302423c Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Fri, 4 Nov 2016 12:12:38 +1030 Subject: [PATCH 4/4] peer: use correct enum in case statement. These are the same, but we're using the ones from state.h instead of the packet types directly. Signed-off-by: Rusty Russell --- daemon/peer.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/daemon/peer.c b/daemon/peer.c index ba1dd1d04..73b6ef61f 100644 --- a/daemon/peer.c +++ b/daemon/peer.c @@ -1469,15 +1469,15 @@ static bool normal_pkt_in(struct peer *peer, const Pkt *pkt) || peer->state == STATE_NORMAL_COMMITTING); switch (pkt->pkt_case) { - case PKT_UPDATE_ADD_HTLC: + case PKT__PKT_UPDATE_ADD_HTLC: err = handle_pkt_htlc_add(peer, pkt); break; - case PKT_UPDATE_FULFILL_HTLC: + case PKT__PKT_UPDATE_FULFILL_HTLC: err = handle_pkt_htlc_fulfill(peer, pkt); break; - case PKT_UPDATE_FAIL_HTLC: + case PKT__PKT_UPDATE_FAIL_HTLC: err = handle_pkt_htlc_fail(peer, pkt); break; @@ -1485,11 +1485,11 @@ static bool normal_pkt_in(struct peer *peer, const Pkt *pkt) err = handle_pkt_feechange(peer, pkt); break; - case PKT_UPDATE_COMMIT: + case PKT__PKT_UPDATE_COMMIT: err = handle_pkt_commit(peer, pkt); break; - case PKT_CLOSE_SHUTDOWN: + case PKT__PKT_CLOSE_SHUTDOWN: err = accept_pkt_close_shutdown(peer, pkt); if (err) break; @@ -1499,7 +1499,7 @@ static bool normal_pkt_in(struct peer *peer, const Pkt *pkt) } return true; - case PKT_UPDATE_REVOCATION: + case PKT__PKT_UPDATE_REVOCATION: if (peer->state == STATE_NORMAL_COMMITTING) { err = handle_pkt_revocation(peer, pkt, STATE_NORMAL); if (!err)