Mercurial > urweb
comparison src/c/request.c @ 2068:b6adfe99bb08
Check realloc's return code to prevent segfault on out of memory condition (Part 2)
author | Sergey Mironov <grrwlf@gmail.com> |
---|---|
date | Sun, 24 Aug 2014 11:56:41 +0400 |
parents | 83bdb52962c9 |
children |
comparison
equal
deleted
inserted
replaced
2067:88841212f0ba | 2068:b6adfe99bb08 |
---|---|
442 if (inputs) { | 442 if (inputs) { |
443 char *name, *value; | 443 char *name, *value; |
444 int len = strlen(inputs); | 444 int len = strlen(inputs); |
445 | 445 |
446 if (len+1 > rc->queryString_size) { | 446 if (len+1 > rc->queryString_size) { |
447 rc->queryString = realloc(rc->queryString, len+1); | 447 char *qs = realloc(rc->queryString, len+1); |
448 if(rc->queryString == NULL) { | 448 if(qs == NULL) { |
449 log_error(logger_data, "queryString is too long (not enough memory)\n"); | 449 log_error(logger_data, "queryString is too long (not enough memory)\n"); |
450 return FAILED; | 450 return FAILED; |
451 } | 451 } |
452 rc->queryString = qs; | |
452 rc->queryString_size = len+1; | 453 rc->queryString_size = len+1; |
453 } | 454 } |
454 strcpy(rc->queryString, inputs); | 455 strcpy(rc->queryString, inputs); |
455 | 456 |
456 while (*inputs) { | 457 while (*inputs) { |
482 size_t path_len = strlen(path); | 483 size_t path_len = strlen(path); |
483 | 484 |
484 on_success(ctx); | 485 on_success(ctx); |
485 | 486 |
486 if (path_len + 1 > rc->path_copy_size) { | 487 if (path_len + 1 > rc->path_copy_size) { |
487 rc->path_copy = realloc(rc->path_copy, path_len + 1); | 488 char *pc = realloc(rc->path_copy, path_len + 1); |
488 if(rc->path_copy == NULL) { | 489 if(pc == NULL) { |
489 log_error(logger_data, "Path is too long (not enough memory)\n"); | 490 log_error(logger_data, "Path is too long (not enough memory)\n"); |
490 return FAILED; | 491 return FAILED; |
491 } | 492 } |
493 rc->path_copy = pc; | |
492 rc->path_copy_size = path_len + 1; | 494 rc->path_copy_size = path_len + 1; |
493 } | 495 } |
494 strcpy(rc->path_copy, path); | 496 strcpy(rc->path_copy, path); |
495 | 497 |
496 uw_set_deadline(ctx, uw_time + uw_time_max); | 498 uw_set_deadline(ctx, uw_time + uw_time_max); |