Mercurial > urweb
changeset 2063:83bdb52962c9
Check realloc's return code to prevent segfault on out of memoty condition
author | Sergey Mironov <grrwlf@gmail.com> |
---|---|
date | Sat, 23 Aug 2014 11:59:34 +0000 (2014-08-23) |
parents | 795b5b75453c |
children | 3dd041b00087 |
files | src/c/request.c |
diffstat | 1 files changed, 10 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- 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);