From 7daa85508314838ce8f0c2cb731827d0f92eb5ee Mon Sep 17 00:00:00 2001 From: Jim Meyering Date: Tue, 31 Jul 2012 12:27:02 +0200 Subject: gsyncd: don't use void* arithmetic; don't leak upon OOM; remove cast (duplexpand): Ignore risk of overflow in computation of the realloc object count, since we'd need a string with 2^62 space-separated tokens to trigger that (that's w/64-bit size_t; w/32-bit it'd be easier, but still improbable). Change-Id: If4521afe7b46110742991dd0ee234284ef8970df BUG: 846755 Signed-off-by: Jim Meyering Reviewed-on: http://review.gluster.com/3793 Tested-by: Gluster Build System Reviewed-by: Anand Avati --- xlators/features/marker/utils/src/gsyncd.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/xlators/features/marker/utils/src/gsyncd.c b/xlators/features/marker/utils/src/gsyncd.c index 3f4c2c4b3..63619b43c 100644 --- a/xlators/features/marker/utils/src/gsyncd.c +++ b/xlators/features/marker/utils/src/gsyncd.c @@ -46,12 +46,14 @@ static int duplexpand (void **buf, size_t tsiz, size_t *len) { size_t osiz = tsiz * *len; - - *buf = realloc (*buf, osiz << 1); - if (!*buf) + char *p = realloc (*buf, osiz << 1); + if (!p) { + free(*buf); return -1; + } - memset ((char *)*buf + osiz, 0, osiz); + memset (p + osiz, 0, osiz); + *buf = p; *len <<= 1; return 0; -- cgit