Commit 29e62e20 authored by Antonin Décimo's avatar Antonin Décimo Committed by Juliusz Chroboczek

Fix potential memory leaks.

parent f8c629a7
...@@ -326,20 +326,24 @@ get_interface_type(int c, int *type_r, gnc_t gnc, void *closure) ...@@ -326,20 +326,24 @@ get_interface_type(int c, int *type_r, gnc_t gnc, void *closure)
static int static int
gethex(int c, unsigned char **value_r, int *len_r, gnc_t gnc, void *closure) gethex(int c, unsigned char **value_r, int *len_r, gnc_t gnc, void *closure)
{ {
char *t; char *t = NULL;
unsigned char *value; unsigned char *value;
int len, rc; int len, rc;
c = getword(c, &t, gnc, closure); c = getword(c, &t, gnc, closure);
if(c < -1) if(c < -1) {
free(t);
return c; return c;
}
len = strlen(t); len = strlen(t);
if(len % 2 != 0) { if(len % 2 != 0) {
free(t); free(t);
return -2; return -2;
} }
value = malloc(len / 2); value = malloc(len / 2);
if(value == NULL) if(value == NULL) {
free(t);
return -2; return -2;
}
rc = fromhex(value, t, len); rc = fromhex(value, t, len);
free(t); free(t);
...@@ -714,7 +718,7 @@ static int ...@@ -714,7 +718,7 @@ static int
parse_ifconf(int c, gnc_t gnc, void *closure, parse_ifconf(int c, gnc_t gnc, void *closure,
struct interface_conf **if_conf_return) struct interface_conf **if_conf_return)
{ {
char *token; char *token = NULL;
struct interface_conf *if_conf; struct interface_conf *if_conf;
if_conf = calloc(1, sizeof(struct interface_conf)); if_conf = calloc(1, sizeof(struct interface_conf));
...@@ -734,6 +738,7 @@ parse_ifconf(int c, gnc_t gnc, void *closure, ...@@ -734,6 +738,7 @@ parse_ifconf(int c, gnc_t gnc, void *closure,
return parse_anonymous_ifconf(c, gnc, closure, if_conf, if_conf_return); return parse_anonymous_ifconf(c, gnc, closure, if_conf, if_conf_return);
error: error:
free(token);
free(if_conf); free(if_conf);
return -2; return -2;
} }
...@@ -763,10 +768,12 @@ parse_key(int c, gnc_t gnc, void *closure, struct key **key_return) ...@@ -763,10 +768,12 @@ parse_key(int c, gnc_t gnc, void *closure, struct key **key_return)
goto error; goto error;
} }
} else if(strcmp(token, "type") == 0) { } else if(strcmp(token, "type") == 0) {
char *auth_type; char *auth_type = NULL;
c = getword(c, &auth_type, gnc, closure); c = getword(c, &auth_type, gnc, closure);
if(c < -1 || auth_type == NULL) if(c < -1 || auth_type == NULL) {
free(auth_type);
goto error; goto error;
}
if(strcmp(auth_type, "none") == 0) { if(strcmp(auth_type, "none") == 0) {
key->type = AUTH_TYPE_NONE; key->type = AUTH_TYPE_NONE;
} else if(strcmp(auth_type, "sha256") == 0) { } else if(strcmp(auth_type, "sha256") == 0) {
...@@ -1078,7 +1085,7 @@ static int ...@@ -1078,7 +1085,7 @@ static int
parse_config_line(int c, gnc_t gnc, void *closure, parse_config_line(int c, gnc_t gnc, void *closure,
int *action_return, const char **message_return) int *action_return, const char **message_return)
{ {
char *token; char *token = NULL;
if(action_return) if(action_return)
*action_return = CONFIG_ACTION_DONE; *action_return = CONFIG_ACTION_DONE;
if(message_return) if(message_return)
...@@ -1089,8 +1096,10 @@ parse_config_line(int c, gnc_t gnc, void *closure, ...@@ -1089,8 +1096,10 @@ parse_config_line(int c, gnc_t gnc, void *closure,
return skip_to_eol(c, gnc, closure); return skip_to_eol(c, gnc, closure);
c = getword(c, &token, gnc, closure); c = getword(c, &token, gnc, closure);
if(c < -1) if(c < -1) {
free(token);
return c; return c;
}
/* Directives allowed in read-only mode */ /* Directives allowed in read-only mode */
if(strcmp(token, "quit") == 0) { if(strcmp(token, "quit") == 0) {
...@@ -1172,17 +1181,20 @@ parse_config_line(int c, gnc_t gnc, void *closure, ...@@ -1172,17 +1181,20 @@ parse_config_line(int c, gnc_t gnc, void *closure,
free(if_conf); free(if_conf);
} }
} else if(strcmp(token, "flush") == 0) { } else if(strcmp(token, "flush") == 0) {
char *token2; char *token2 = NULL;
c = skip_whitespace(c, gnc, closure); c = skip_whitespace(c, gnc, closure);
c = getword(c, &token2, gnc, closure); c = getword(c, &token2, gnc, closure);
if(c < -1) if(c < -1) {
free(token2);
goto fail; goto fail;
}
if(strcmp(token2, "interface") == 0) { if(strcmp(token2, "interface") == 0) {
char *ifname; char *ifname = NULL;
int rc; int rc;
c = getword(c, &ifname, gnc, closure); c = getword(c, &ifname, gnc, closure);
c = skip_eol(c, gnc, closure); c = skip_eol(c, gnc, closure);
if(c < -1) { if(c < -1) {
free(ifname);
free(token2); free(token2);
goto fail; goto fail;
} }
...@@ -1209,12 +1221,12 @@ parse_config_line(int c, gnc_t gnc, void *closure, ...@@ -1209,12 +1221,12 @@ parse_config_line(int c, gnc_t gnc, void *closure,
goto fail; goto fail;
reopen_logfile(); reopen_logfile();
} else if(strcmp(token, "key") == 0) { } else if(strcmp(token, "key") == 0) {
struct key *key = NULL; struct key *key = NULL;
c = parse_key(c, gnc, closure, &key); c = parse_key(c, gnc, closure, &key);
if(c < -1) if(c < -1 || key == NULL || key->id == NULL) {
free(key);
goto fail; goto fail;
if(key->id == NULL) }
goto fail;
switch(key->type) { switch(key->type) {
case AUTH_TYPE_SHA256: case AUTH_TYPE_SHA256:
if(key->len != 32) { if(key->len != 32) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment