From b3ab56c2bf35214b6ef81027b0a08c09e3dc916f Mon Sep 17 00:00:00 2001 From: William Roberts <w.roberts@sta.samsung.com> Date: Mon, 17 Sep 2012 14:35:02 -0700 Subject: [PATCH] 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 --- check_seapp/check_seapp.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/check_seapp/check_seapp.c b/check_seapp/check_seapp.c index d3a5dda8b..93ecb2fe1 100644 --- a/check_seapp/check_seapp.c +++ b/check_seapp/check_seapp.c @@ -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*/ 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; } -- GitLab