diff options
author | Riccardo Spagni <ric@spagni.net> | 2015-12-30 12:28:03 +0200 |
---|---|---|
committer | Riccardo Spagni <ric@spagni.net> | 2015-12-30 12:28:03 +0200 |
commit | 7223eebbe71833e895fca95267cb243834dedf83 (patch) | |
tree | a5d48783316ff837e353c51a29b54f5324dd0bb1 /external/miniupnpc/minihttptestserver.c | |
parent | Merge pull request #575 (diff) | |
parent | no longer need to pass the size to rapidjson (diff) | |
download | monero-7223eebbe71833e895fca95267cb243834dedf83.tar.xz |
Merge pull request #577
32a2633 no longer need to pass the size to rapidjson (Riccardo Spagni)
bd8e0fd add missing miniupnpc files, modify cmake to not build miniupnpc tests and to fix an issue with finding miniupnpcstrings (Riccardo Spagni)
7da9905 updated miniupnpc (Riccardo Spagni)
Diffstat (limited to 'external/miniupnpc/minihttptestserver.c')
-rw-r--r-- | external/miniupnpc/minihttptestserver.c | 46 |
1 files changed, 37 insertions, 9 deletions
diff --git a/external/miniupnpc/minihttptestserver.c b/external/miniupnpc/minihttptestserver.c index fb779650b..6663bc081 100644 --- a/external/miniupnpc/minihttptestserver.c +++ b/external/miniupnpc/minihttptestserver.c @@ -1,7 +1,7 @@ -/* $Id: minihttptestserver.c,v 1.16 2014/04/01 15:08:28 nanard Exp $ */ +/* $Id: minihttptestserver.c,v 1.19 2015/11/17 09:07:17 nanard Exp $ */ /* Project : miniUPnP * Author : Thomas Bernard - * Copyright (c) 2011-2014 Thomas Bernard + * Copyright (c) 2011-2015 Thomas Bernard * This software is subject to the conditions detailed in the * LICENCE file provided in this distribution. * */ @@ -18,6 +18,10 @@ #include <time.h> #include <errno.h> +#ifndef INADDR_LOOPBACK +#define INADDR_LOOPBACK 0x7f000001 +#endif + #define CRAP_LENGTH (2048) volatile sig_atomic_t quit = 0; @@ -104,6 +108,8 @@ char * build_chunked_response(int content_length, int * response_len) /* allocate to have some margin */ buffer_length = 256 + content_length + (content_length >> 4); response_buffer = malloc(buffer_length); + if(response_buffer == NULL) + return NULL; *response_len = snprintf(response_buffer, buffer_length, "HTTP/1.1 200 OK\r\n" "Content-Type: text/plain\r\n" @@ -112,6 +118,10 @@ char * build_chunked_response(int content_length, int * response_len) /* build the content */ content_buffer = malloc(content_length); + if(content_buffer == NULL) { + free(response_buffer); + return NULL; + } build_content(content_buffer, content_length); /* chunk it */ @@ -414,7 +424,14 @@ void handle_http_connection(int c) "Content-Length: %d\r\n" "\r\n", content_length); response_len = content_length+n+CRAP_LENGTH; - response_buffer = realloc(response_buffer, response_len); + p = realloc(response_buffer, response_len); + if(p == NULL) { + /* error 500 */ + free(response_buffer); + response_buffer = NULL; + break; + } + response_buffer = p; build_content(response_buffer + n, content_length); build_crap(response_buffer + n + content_length, CRAP_LENGTH); break; @@ -445,7 +462,14 @@ void handle_http_connection(int c) "Content-Type: text/plain\r\n" "\r\n"); response_len = content_length+n; - response_buffer = realloc(response_buffer, response_len); + p = realloc(response_buffer, response_len); + if(p == NULL) { + /* Error 500 */ + free(response_buffer); + response_buffer = NULL; + break; + } + response_buffer = p; build_content(response_buffer + n, response_len - n); } @@ -564,12 +588,16 @@ int main(int argc, char * * argv) { if(f) { char * buffer; buffer = malloc(16*1024); - build_content(buffer, 16*1024); - i = fwrite(buffer, 1, 16*1024, f); - if(i != 16*1024) { - fprintf(stderr, "error writing to file %s : %dbytes written (out of %d)\n", expected_file_name, i, 16*1024); + if(buffer == NULL) { + fprintf(stderr, "memory allocation error\n"); + } else { + build_content(buffer, 16*1024); + i = fwrite(buffer, 1, 16*1024, f); + if(i != 16*1024) { + fprintf(stderr, "error writing to file %s : %dbytes written (out of %d)\n", expected_file_name, i, 16*1024); + } + free(buffer); } - free(buffer); fclose(f); } else { fprintf(stderr, "error opening file %s for writing\n", expected_file_name); |