From 3d80c086bea3b0d93327c30ac620740b629cb294 Mon Sep 17 00:00:00 2001 From: Alexander Færøy Date: Sat, 23 Jun 2018 11:54:36 +0200 Subject: Fix memory leak in decode_link_specifiers(). This patch fixes a memory leak in decode_link_specifiers() where the hs_spec variable might leak if the default label is taken in the switch/case expression. See: Coverity CID 1437437. --- src/or/hs_descriptor.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/or/hs_descriptor.c b/src/or/hs_descriptor.c index 938b7a77df..15bdd14d55 100644 --- a/src/or/hs_descriptor.c +++ b/src/or/hs_descriptor.c @@ -864,6 +864,7 @@ decode_link_specifiers(const char *encoded) sizeof(hs_spec->u.legacy_id)); break; default: + tor_free(hs_spec); goto err; } -- cgit v1.2.3-54-g00ecf From c997d49ad6e6a360323311444eed1dbee785aea4 Mon Sep 17 00:00:00 2001 From: Alexander Færøy Date: Sat, 23 Jun 2018 12:39:20 +0200 Subject: Fix memory link in test_link_specifier(). This patch fixes a memory leak in test_link_specifier() where ls might not get freed in case one of the test macros fails. See: Coverity CID 1437434. --- src/test/test_hs_descriptor.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/test/test_hs_descriptor.c b/src/test/test_hs_descriptor.c index 97fe1910b8..365683e75c 100644 --- a/src/test/test_hs_descriptor.c +++ b/src/test/test_hs_descriptor.c @@ -376,6 +376,9 @@ test_link_specifier(void *arg) ssize_t ret; hs_desc_link_specifier_t spec; smartlist_t *link_specifiers = smartlist_new(); + char buf[256]; + char *b64 = NULL; + link_specifier_t *ls = NULL; (void) arg; @@ -385,9 +388,7 @@ test_link_specifier(void *arg) /* Test IPv4 for starter. */ { - char *b64, buf[256]; uint32_t ipv4; - link_specifier_t *ls; spec.type = LS_IPV4; ret = tor_addr_parse(&spec.u.ap.addr, "1.2.3.4"); @@ -414,9 +415,7 @@ test_link_specifier(void *arg) /* Test IPv6. */ { - char *b64, buf[256]; uint8_t ipv6[16]; - link_specifier_t *ls; spec.type = LS_IPV6; ret = tor_addr_parse(&spec.u.ap.addr, "[1:2:3:4::]"); @@ -445,9 +444,7 @@ test_link_specifier(void *arg) /* Test legacy. */ { - char *b64, buf[256]; uint8_t *id; - link_specifier_t *ls; spec.type = LS_LEGACY_ID; memset(spec.u.legacy_id, 'Y', sizeof(spec.u.legacy_id)); @@ -473,6 +470,8 @@ test_link_specifier(void *arg) } done: + link_specifier_free(ls); + tor_free(b64); smartlist_free(link_specifiers); } -- cgit v1.2.3-54-g00ecf