libmicrohttpd

HTTP/1.x server C library (MHD 1.x, stable)
Log | Files | Refs | Submodules | README | LICENSE

commit c81afd7682d237044b5869791c72824877546d60
parent d064f75e0d63f098cfe9f7e3c0e4dfb930445ace
Author: Andrey Uzunov <andrey.uzunov@gmail.com>
Date:   Sat, 28 Dec 2013 18:43:28 +0000

spdy: fixed bug when adding header with NULL value

Diffstat:
Msrc/examples/spdy_fileserver.c | 22++++++++++++++--------
Msrc/microspdy/structures.c | 21++++++++++++++++-----
Msrc/testspdy/test_struct_namevalue.c | 2+-
3 files changed, 31 insertions(+), 14 deletions(-)

diff --git a/src/examples/spdy_fileserver.c b/src/examples/spdy_fileserver.c @@ -44,18 +44,24 @@ char* basedir; #define GET_MIME_TYPE(fname, mime) do {\ unsigned int __len = strlen(fname);\ - if (__len < 4 || '.' != (fname)[__len - 4]) break;\ - const char * __ext = &(fname)[__len - 3];\ - if(0 == strcmp(__ext, "jpg")) (mime) = strdup("image/jpeg");\ - else if(0 == strcmp(__ext, "png")) (mime) = strdup("image/png");\ - else if(0 == strcmp(__ext, "css")) (mime) = strdup("text/css");\ - else if(0 == strcmp(__ext, "gif")) (mime) = strdup("image/gif");\ - else if(0 == strcmp(__ext, "htm")) (mime) = strdup("text/html");\ - else \ + if (__len < 4 || '.' != (fname)[__len - 4]) \ { \ (mime) = strdup("application/octet-stream");\ printf("MIME for %s is applic...\n", (fname));\ }\ + else {\ + const char * __ext = &(fname)[__len - 3];\ + if(0 == strcmp(__ext, "jpg")) (mime) = strdup("image/jpeg");\ + else if(0 == strcmp(__ext, "png")) (mime) = strdup("image/png");\ + else if(0 == strcmp(__ext, "css")) (mime) = strdup("text/css");\ + else if(0 == strcmp(__ext, "gif")) (mime) = strdup("image/gif");\ + else if(0 == strcmp(__ext, "htm")) (mime) = strdup("text/html");\ + else \ + { \ + (mime) = strdup("application/octet-stream");\ + printf("MIME for %s is applic...\n", (fname));\ + }\ + }\ if(NULL == (mime))\ {\ printf("no memory\n");\ diff --git a/src/microspdy/structures.c b/src/microspdy/structures.c @@ -64,8 +64,10 @@ SPDY_name_value_add (struct SPDY_NameValue *container, char **temp_value; char *temp_string; - if(NULL == container || NULL == name || 0 == (len = strlen(name))) + if(NULL == container || NULL == name || NULL == value || 0 == (len = strlen(name))) return SPDY_INPUT_ERROR; + //TODO there is old code handling value==NULL + //update it to handle strlen(value)==0 for(i=0; i<len; ++i) { @@ -85,7 +87,9 @@ SPDY_name_value_add (struct SPDY_NameValue *container, free(container->name); return SPDY_NO; } - if (NULL == (container->value[0] = strdup (value))) + /*if(NULL == value) + container->value[0] = NULL; + else */if (NULL == (container->value[0] = strdup (value))) { free(container->value); free(container->name); @@ -125,7 +129,9 @@ SPDY_name_value_add (struct SPDY_NameValue *container, free(pair); return SPDY_NO; } - if (NULL == (pair->value[0] = strdup (value))) + /*if(NULL == value) + pair->value[0] = NULL; + else */if (NULL == (pair->value[0] = strdup (value))) { free(pair->value); free(pair->name); @@ -477,6 +483,8 @@ SPDYF_name_value_to_stream(struct SPDY_NameValue * container[], for(i=0; i<iterator->num_values; ++i) { + //if(NULL == iterator->value[i]) + // continue; size += strlen(iterator->value[i]); // string if(i/* || !strlen(iterator->value[i])*/) ++size; //NULL separator } @@ -518,8 +526,11 @@ SPDYF_name_value_to_stream(struct SPDY_NameValue * container[], ++offset; //if(!i) continue; } - strncpy(*stream + offset, iterator->value[i], strlen(iterator->value[i])); - offset += strlen(iterator->value[i]); + //else if(NULL != iterator->value[i]) + //{ + strncpy(*stream + offset, iterator->value[i], strlen(iterator->value[i])); + offset += strlen(iterator->value[i]); + //} } value_size = offset - value_offset - 4; value_size = htonl(value_size); diff --git a/src/testspdy/test_struct_namevalue.c b/src/testspdy/test_struct_namevalue.c @@ -165,7 +165,7 @@ main() SPDY_name_value_destroy(container); //check everything with NULL values - for(i=0; i<6; ++i) + for(i=0; i<7; ++i) { printf("%i ",i); ob1 = (i & 4) ? data : NULL;