Skip to content
Snippets Groups Projects
Commit b3ab56c2 authored by William Roberts's avatar William Roberts
Browse files

Fix for segfault/jmp depends on unitialized variable

When realloc creates the first block of memory, it must
be initialized to NULL for the following strcat functions
to operate correctly.

Change-Id: I98fc14e1b19de5aa205354d16e54445293430d8e
parent a53ccf39
No related branches found
No related tags found
No related merge requests found
...@@ -499,19 +499,23 @@ static rule_map *rule_map_new(kvp keys[], unsigned int num_of_keys, int lineno) ...@@ -499,19 +499,23 @@ static rule_map *rule_map_new(kvp keys[], unsigned int num_of_keys, int lineno)
/* Only build key off of inputs*/ /* Only build key off of inputs*/
if (r->dir == dir_in) { if (r->dir == dir_in) {
char *tmp; char *tmp;
int l = strlen(k->key); int key_len = strlen(k->key);
l += strlen(k->value); int val_len = strlen(k->value);
l += (new_map->key) ? strlen(new_map->key) : 0; int l = (new_map->key) ? strlen(new_map->key) : 0;
l = l + key_len + val_len;
l += 1; l += 1;
tmp = realloc(new_map->key, l); tmp = realloc(new_map->key, l);
if (!tmp) if (!tmp)
goto oom; goto oom;
if (!new_map->key)
memset(tmp, 0, l);
new_map->key = tmp; new_map->key = tmp;
strcat(new_map->key, k->key); strncat(new_map->key, k->key, key_len);
strcat(new_map->key, k->value); strncat(new_map->key, k->value, val_len);
} }
break; break;
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment