aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEvgeny Grin (Karlson2k) <k2k@narod.ru>2022-11-07 11:49:36 +0300
committerEvgeny Grin (Karlson2k) <k2k@narod.ru>2022-11-07 13:51:37 +0300
commita37a83ff3ea2249b87176113dfb3e4ae2fec524e (patch)
tree47b9481b2d8230a061ca3be657cb3b4bf5ed669b
parent1ffe7932df675100f7260393c24f307b83fa95b4 (diff)
downloadlibmicrohttpd-a37a83ff3ea2249b87176113dfb3e4ae2fec524e.tar.gz
libmicrohttpd-a37a83ff3ea2249b87176113dfb3e4ae2fec524e.zip
testcurl: fixed checking response headers as null-terminated string
-rw-r--r--src/testcurl/test_get_close_keep_alive.c6
-rw-r--r--src/testcurl/test_head.c12
-rw-r--r--src/testcurl/test_toolarge.c11
3 files changed, 21 insertions, 8 deletions
diff --git a/src/testcurl/test_get_close_keep_alive.c b/src/testcurl/test_get_close_keep_alive.c
index 2eb29285..81f7576c 100644
--- a/src/testcurl/test_get_close_keep_alive.c
+++ b/src/testcurl/test_get_close_keep_alive.c
@@ -162,7 +162,7 @@ _libcurlErrorExit_func (const char *errDesc, const char *funcName, int lineNum)
162#define HDR_CONN_CLOSE_VALUE "close" 162#define HDR_CONN_CLOSE_VALUE "close"
163#define HDR_CONN_CLOSE MHD_HTTP_HEADER_CONNECTION ": " \ 163#define HDR_CONN_CLOSE MHD_HTTP_HEADER_CONNECTION ": " \
164 HDR_CONN_CLOSE_VALUE 164 HDR_CONN_CLOSE_VALUE
165#define HDR_CONN_KEEP_ALIVE_VALUE "keep-alive" 165#define HDR_CONN_KEEP_ALIVE_VALUE "Keep-Alive"
166#define HDR_CONN_KEEP_ALIVE MHD_HTTP_HEADER_CONNECTION ": " \ 166#define HDR_CONN_KEEP_ALIVE MHD_HTTP_HEADER_CONNECTION ": " \
167 HDR_CONN_KEEP_ALIVE_VALUE 167 HDR_CONN_KEEP_ALIVE_VALUE
168 168
@@ -255,10 +255,10 @@ lcurl_hdr_callback (char *buffer, size_t size, size_t nitems,
255 strlen (MHD_HTTP_VERSION_1_0)))) 255 strlen (MHD_HTTP_VERSION_1_0))))
256 check_res->found_http10 = 1; 256 check_res->found_http10 = 1;
257 else if ((data_size == strlen (HDR_CONN_CLOSE) + 2) && 257 else if ((data_size == strlen (HDR_CONN_CLOSE) + 2) &&
258 (0 == strncasecmp (buffer, HDR_CONN_CLOSE "\r\n", data_size))) 258 (0 == memcmp (buffer, HDR_CONN_CLOSE "\r\n", data_size)))
259 check_res->found_conn_close = 1; 259 check_res->found_conn_close = 1;
260 else if ((data_size == strlen (HDR_CONN_KEEP_ALIVE) + 2) && 260 else if ((data_size == strlen (HDR_CONN_KEEP_ALIVE) + 2) &&
261 (0 == strncasecmp (buffer, HDR_CONN_KEEP_ALIVE "\r\n", data_size))) 261 (0 == memcmp (buffer, HDR_CONN_KEEP_ALIVE "\r\n", data_size)))
262 check_res->found_conn_keep_alive = 1; 262 check_res->found_conn_keep_alive = 1;
263 263
264 return data_size; 264 return data_size;
diff --git a/src/testcurl/test_head.c b/src/testcurl/test_head.c
index 3c984125..066688b6 100644
--- a/src/testcurl/test_head.c
+++ b/src/testcurl/test_head.c
@@ -274,10 +274,13 @@ lcurl_hdr_callback (char *buffer, size_t size, size_t nitems,
274 int res; 274 int res;
275 const unsigned int numbers_pos = 275 const unsigned int numbers_pos =
276 MHD_STATICSTR_LEN_ (MHD_HTTP_HEADER_CONTENT_LENGTH ": "); 276 MHD_STATICSTR_LEN_ (MHD_HTTP_HEADER_CONTENT_LENGTH ": ");
277 res = snprintf (cmpbuf, sizeof(cmpbuf), "%u\r\n", check_res->expected_size); 277 res = snprintf (cmpbuf, sizeof(cmpbuf), "%u", check_res->expected_size);
278 if ((res <= 0) || (res > ((int) (sizeof(cmpbuf) - 1)))) 278 if ((res <= 0) || (res > ((int) (sizeof(cmpbuf) - 1))))
279 externalErrorExit (); 279 externalErrorExit ();
280 if (0 != strcmp (buffer + numbers_pos, cmpbuf)) 280 if (data_size - numbers_pos <= 2)
281 mhdErrorExitDesc ("Broken Content-Length");
282 else if ((((size_t) res + 2) != data_size - numbers_pos) ||
283 (0 != memcmp (buffer + numbers_pos, cmpbuf, (size_t) res)))
281 { 284 {
282 fprintf (stderr, "Wrong Content-Length.\n" 285 fprintf (stderr, "Wrong Content-Length.\n"
283 "Expected:\n%u\n" 286 "Expected:\n%u\n"
@@ -285,6 +288,11 @@ lcurl_hdr_callback (char *buffer, size_t size, size_t nitems,
285 buffer + numbers_pos); 288 buffer + numbers_pos);
286 mhdErrorExitDesc ("Wrong Content-Length"); 289 mhdErrorExitDesc ("Wrong Content-Length");
287 } 290 }
291 else if (0 != memcmp ("\r\n", buffer + data_size - 2, 2))
292 {
293 mhdErrorExitDesc ("The Content-Length header is not " \
294 "terminated by CRLF");
295 }
288 check_res->size_found++; 296 check_res->size_found++;
289 } 297 }
290 298
diff --git a/src/testcurl/test_toolarge.c b/src/testcurl/test_toolarge.c
index e6c291e2..05e497a7 100644
--- a/src/testcurl/test_toolarge.c
+++ b/src/testcurl/test_toolarge.c
@@ -273,12 +273,17 @@ lcurl_hdr_callback (char *buffer, size_t size, size_t nitems,
273 check_res->num_n1_headers++; 273 check_res->num_n1_headers++;
274 else if ((5 <= data_size) && ('0' == buffer[0])) 274 else if ((5 <= data_size) && ('0' == buffer[0]))
275 { 275 {
276 const char *const col_ptr = strstr (buffer, ": "); 276 const char *const col_ptr = memchr (buffer, ':', data_size);
277 if (0 != check_res->large_header_value_size) 277 if (0 != check_res->large_header_value_size)
278 mhdErrorExitDesc ("Expected only one large header, " \ 278 mhdErrorExitDesc ("Expected only one large header, " \
279 "but found two large headers in the reply"); 279 "but found two large headers in the reply");
280 check_res->large_header_valid = 0; 280 if (NULL == col_ptr)
281 if (NULL != col_ptr) 281 check_res->large_header_valid = 0;
282 else if ((size_t) (col_ptr - buffer) >= data_size - 2)
283 check_res->large_header_valid = 0;
284 else if (*(col_ptr + 1) != ' ')
285 check_res->large_header_valid = 0;
286 else
282 { 287 {
283 const char *const name = buffer; 288 const char *const name = buffer;
284 const size_t name_len = (size_t) (col_ptr - buffer); 289 const size_t name_len = (size_t) (col_ptr - buffer);