From 047d69c4eb2cefe9bab654fb570592d3863da792 Mon Sep 17 00:00:00 2001 From: Tobias Klauser Date: Mon, 7 Sep 2015 17:24:56 +0200 Subject: curvetun: Fix issues detected by the Coverity scanner Fix two issues detected by the Coverity scanner (CID 991819 & CID 991822) Signed-off-by: Tobias Klauser --- curvetun.c | 4 ++-- curvetun_mgmt_users.c | 13 ++++++++++--- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/curvetun.c b/curvetun.c index 52bfb44..7507a75 100644 --- a/curvetun.c +++ b/curvetun.c @@ -328,7 +328,7 @@ static void check_config_keypair_or_die(char *home) if (fd < 0) { err = EIO; errstr = "Cannot open privkey file!\n"; - goto out; + goto out_noclose; } ret = read(fd, secretkey, sizeof(secretkey)); @@ -368,7 +368,7 @@ static void check_config_keypair_or_die(char *home) } out: close(fd); - +out_noclose: xmemset(publickey, 0, sizeof(publickey)); xmemset(publicres, 0, sizeof(publicres)); xmemset(secretkey, 0, sizeof(secretkey)); diff --git a/curvetun_mgmt_users.c b/curvetun_mgmt_users.c index 665ceb3..52b20d8 100644 --- a/curvetun_mgmt_users.c +++ b/curvetun_mgmt_users.c @@ -206,17 +206,23 @@ static int parse_line(char *line, char *homedir) for (; str != NULL;) { switch (s) { case PARSE_USERNAME: - if (__check_duplicate_username(str, strlen(str) + 1)) + if (__check_duplicate_username(str, strlen(str) + 1)) { + user_store_free(elem); return -EINVAL; + } strlcpy(elem->username, str, sizeof(elem->username)); s = PARSE_PUBKEY; break; case PARSE_PUBKEY: if (!curve25519_pubkey_hexparse_32(pkey, sizeof(pkey), - str, strlen(str))) + str, strlen(str))) { + user_store_free(elem); return -EINVAL; - if (__check_duplicate_pubkey(pkey, sizeof(pkey))) + } + if (__check_duplicate_pubkey(pkey, sizeof(pkey))) { + user_store_free(elem); return -EINVAL; + } memcpy(elem->publickey, pkey, sizeof(elem->publickey)); curve25519_proto_init(&elem->proto_inf, elem->publickey, sizeof(elem->publickey)); s = PARSE_DONE; @@ -224,6 +230,7 @@ static int parse_line(char *line, char *homedir) case PARSE_DONE: break; default: + user_store_free(elem); return -EIO; } -- cgit v1.2.3-54-g00ecf