From 1f48013e88bb332ee40e0aa13972d7aaa0916ead Mon Sep 17 00:00:00 2001 From: klebertarcisio Date: Wed, 21 Apr 2021 09:51:29 -0300 Subject: [PATCH] Avoid null pointer dereference --- src/dyn_test.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/dyn_test.c b/src/dyn_test.c index 85df5d352..1ba7e908a 100644 --- a/src/dyn_test.c +++ b/src/dyn_test.c @@ -212,6 +212,9 @@ static rstatus_t init_peer(struct node *s) { // s->tokens = cseed->tokens; struct sockinfo *info = malloc(sizeof(struct sockinfo)); + if (!info) { + return DN_ERROR; + } memset(info, 0, sizeof(*info)); dn_resolve(&name, s->endpoint.port, info); @@ -659,6 +662,10 @@ int main(int argc, char **argv) { init_test(argc, argv); struct node *peer = malloc(sizeof(struct node)); + if (!peer) { + loga("Out of memory !!!"); + goto err_out; + } memset(peer, 0, sizeof(struct node)); init_peer(peer);