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
diff --git a/check_seapp/check_seapp.c b/check_seapp/check_seapp.c
index d3a5dda..93ecb2f 100644
--- a/check_seapp/check_seapp.c
+++ b/check_seapp/check_seapp.c
@@ -499,19 +499,23 @@
/* Only build key off of inputs*/
if (r->dir == dir_in) {
char *tmp;
- int l = strlen(k->key);
- l += strlen(k->value);
- l += (new_map->key) ? strlen(new_map->key) : 0;
+ int key_len = strlen(k->key);
+ int val_len = strlen(k->value);
+ int l = (new_map->key) ? strlen(new_map->key) : 0;
+ l = l + key_len + val_len;
l += 1;
tmp = realloc(new_map->key, l);
if (!tmp)
goto oom;
+ if (!new_map->key)
+ memset(tmp, 0, l);
+
new_map->key = tmp;
- strcat(new_map->key, k->key);
- strcat(new_map->key, k->value);
+ strncat(new_map->key, k->key, key_len);
+ strncat(new_map->key, k->value, val_len);
}
break;
}