From 58b724ef885d0a5d959096d494c09d69f4888c2f Mon Sep 17 00:00:00 2001 From: alexhudson Date: Wed, 4 Jul 2007 08:45:46 +0000 Subject: [PATCH] Make BongoJsonJPathGetString() allocate memory for the caller --- src/agents/avirus/avirus.c | 6 ++---- src/libs/json/json.c | 3 ++- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/src/agents/avirus/avirus.c b/src/agents/avirus/avirus.c index d3ff367..5a51756 100755 --- a/src/agents/avirus/avirus.c +++ b/src/agents/avirus/avirus.c @@ -1208,10 +1208,7 @@ ReadConfiguration(void) } res = BongoJsonJPathGetInt(node, "o:flags/i", &AVirus.flags); - res = BongoJsonJPathGetString(node, "o:patterns/s", &tmpBuffer); - if (res == BONGO_JSON_OK) { - strncpy(AVirus.path.patterns, tmpBuffer, XPL_MAX_PATH); - } + res = BongoJsonJPathGetString(node, "o:patterns/s", &AVirus.path.patterns); res = BongoJsonJPathGetInt(node, "o:queue/i", (int *)&AVirus.nmap.queue); res = BongoJsonJPathGetString(node, "o:host/s", &tmpBuffer); if (res == BONGO_JSON_OK) { @@ -1220,6 +1217,7 @@ ReadConfiguration(void) if (he) { memcpy(&AVirus.clam.addr.sin_addr.s_addr, he->h_addr_list[0], sizeof(AVirus.clam.addr.sin_addr.s_addr)); } + MemFree(tmpBuffer); } else { AVirus.clam.addr.sin_addr.s_addr = inet_addr(CLAMAV_DEFAULT_ADDRESS); } diff --git a/src/libs/json/json.c b/src/libs/json/json.c index bd803ed..aae8792 100644 --- a/src/libs/json/json.c +++ b/src/libs/json/json.c @@ -172,10 +172,11 @@ BongoJsonJPathGetFloat(BongoJsonNode *n, const char *path, float *val) { } BongoJsonResult BongoJsonJPathGetString(BongoJsonNode *n, const char *path, const char **val) { + // caller must free the memory allocated BongoJsonNode *result = BongoJsonJPath(n, path); if (!result) return BONGO_JSON_NOT_FOUND; if (result->type == BONGO_JSON_STRING) { - *val = BongoJsonNodeAsString(result); + *val = MemStrdup(BongoJsonNodeAsString(result)); return BONGO_JSON_OK; } return BONGO_JSON_BAD_TYPE;