# HG changeset patch # User Sergey Mironov # Date 1408795174 0 # Node ID 83bdb52962c901eac6c6294ce1590490ab593711 # Parent 795b5b75453c79a13e1b334331cf1ae40b1d6ab2 Check realloc's return code to prevent segfault on out of memoty condition diff -r 795b5b75453c -r 83bdb52962c9 src/c/request.c --- a/src/c/request.c Mon Jul 07 10:05:04 2014 +0400 +++ b/src/c/request.c Sat Aug 23 11:59:34 2014 +0000 @@ -444,8 +444,12 @@ int len = strlen(inputs); if (len+1 > rc->queryString_size) { + rc->queryString = realloc(rc->queryString, len+1); + if(rc->queryString == NULL) { + log_error(logger_data, "queryString is too long (not enough memory)\n"); + return FAILED; + } rc->queryString_size = len+1; - rc->queryString = realloc(rc->queryString, len+1); } strcpy(rc->queryString, inputs); @@ -480,8 +484,12 @@ 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) { + log_error(logger_data, "Path is too long (not enough memory)\n"); + return FAILED; + } rc->path_copy_size = path_len + 1; - rc->path_copy = realloc(rc->path_copy, rc->path_copy_size); } strcpy(rc->path_copy, path);