From a2f18ae0234bc6dbccaebd21bc7ea07ceac2ee7a Mon Sep 17 00:00:00 2001 From: Jesper Jensen Date: Mon, 14 Apr 2025 13:06:26 +0200 Subject: Don't crash on invalid dictionary --- src/proto.c | 7 +++++-- src/query.c | 12 ++++++++---- 2 files changed, 13 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/proto.c b/src/proto.c index 4ea9b20..d4f8b59 100644 --- a/src/proto.c +++ b/src/proto.c @@ -368,7 +368,8 @@ PROCESS_REPONSE(getclient_response) { bcur_next(&bcursor, 1); break; case -BENC_EBADP: - fatal("Bad dict"); + err("Bad Dictionary, Discard packet"); + return PROTO_EDISC; } } @@ -763,7 +764,9 @@ int proto_run(struct dht* dht, char* buff, size_t recv_len, struct sockaddr_in* break; } case -BENC_EBADP: - fatal("Bad dict"); + err("Bad Dictionary, we drop this packet"); + recalulate_waketime(dht); + return 0; } } diff --git a/src/query.c b/src/query.c index f0b9014..2276ac1 100644 --- a/src/query.c +++ b/src/query.c @@ -64,7 +64,8 @@ int handle_request(struct nodeid* self, struct tokens *tokens, time_t now, const bcur_next(&bcursor, 1); break; case -BENC_EBADP: - fatal("Bad dict"); + err("Bad query: Bad Dictionary"); + return QUERY_EBADQ; } } @@ -135,7 +136,8 @@ int handle_request(struct nodeid* self, struct tokens *tokens, time_t now, const bcur_next(&bcursor, 1); break; case -BENC_EBADP: - fatal("Bad dict"); + err("Bad query: Bad Dictionary"); + return QUERY_EBADQ; } } @@ -233,7 +235,8 @@ int handle_request(struct nodeid* self, struct tokens *tokens, time_t now, const bcur_next(&bcursor, 1); break; case -BENC_EBADP: - fatal("Bad dict"); + err("Bad query: Bad Dictionary"); + return QUERY_EBADQ; } } @@ -443,7 +446,8 @@ int handle_request(struct nodeid* self, struct tokens *tokens, time_t now, const bcur_next(&bcursor, 1); break; case -BENC_EBADP: - fatal("Bad dict"); + err("Bad query: Bad Dictionary"); + return QUERY_EBADQ; } } -- cgit v1.2.3