From 1bbc50639256f0a04b1866ad23a3945c17130068 Mon Sep 17 00:00:00 2001 From: Sergey Mironov Date: Sun, 24 Aug 2014 11:56:41 +0400 Subject: Check realloc's return code to prevent segfault on out of memory condition (Part 2) --- src/c/request.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'src/c/request.c') diff --git a/src/c/request.c b/src/c/request.c index 9dc6aa59..d621aea7 100644 --- a/src/c/request.c +++ b/src/c/request.c @@ -444,11 +444,12 @@ request_result uw_request(uw_request_context rc, uw_context ctx, int len = strlen(inputs); if (len+1 > rc->queryString_size) { - rc->queryString = realloc(rc->queryString, len+1); - if(rc->queryString == NULL) { + char *qs = realloc(rc->queryString, len+1); + if(qs == NULL) { log_error(logger_data, "queryString is too long (not enough memory)\n"); return FAILED; } + rc->queryString = qs; rc->queryString_size = len+1; } strcpy(rc->queryString, inputs); @@ -484,11 +485,12 @@ request_result uw_request(uw_request_context rc, uw_context ctx, on_success(ctx); if (path_len + 1 > rc->path_copy_size) { - rc->path_copy = realloc(rc->path_copy, path_len + 1); - if(rc->path_copy == NULL) { + char *pc = realloc(rc->path_copy, path_len + 1); + if(pc == NULL) { log_error(logger_data, "Path is too long (not enough memory)\n"); return FAILED; } + rc->path_copy = pc; rc->path_copy_size = path_len + 1; } strcpy(rc->path_copy, path); -- cgit v1.2.3