Skip to content

Commit b06639f

Browse files
committed
http: do not search outside the header value
Header values in picohttp are not null-terminated so `strstr` would happily search outside the header value and exceed the length of the header value. This could lead to DoS in artifical circumstances which don't apply to fd in practice. There is always a null byte in memory _somewhere_ after the header value even if it is not actually part of the header value. This is because `fd_http_server_ws_frame`s are allocated after the request buffer that contains the headers and the ws_frames contain four bytes of padding that is zero, because the whole memory we're operating on, has been allocated with `mmap` anonymously which zeroes the memory QED.
1 parent b2c7680 commit b06639f

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

src/waltz/http/fd_http_server.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -575,13 +575,14 @@ read_conn_http( fd_http_server_t * http,
575575

576576
conn->upgrade_websocket = 0;
577577
int compress_websocket = 0;
578-
if( FD_UNLIKELY( upgrade_key && !strncmp( upgrade_key, "websocket", 9UL ) ) ) {
578+
if( FD_UNLIKELY( upgrade_key && !strncasecmp( upgrade_key, "websocket", 9UL ) ) ) {
579579
conn->request_bytes_len = (ulong)result;
580580
conn->upgrade_websocket = 1;
581581

582582
#if FD_HAS_ZSTD
583583
for( ulong i=0UL; i<num_headers; i++ ) {
584-
if( FD_LIKELY( headers[ i ].name_len==22UL && !strncasecmp( headers[ i ].name, "Sec-WebSocket-Protocol", 22UL ) && strstr( headers[ i ].value, "compress-zstd" ) ) ) {
584+
if( FD_LIKELY( headers[ i ].name_len==22UL && !strncasecmp( headers[ i ].name, "Sec-WebSocket-Protocol", 22UL ) &&
585+
headers[ i ].value_len==13UL && !strncmp( headers[ i ].value, "compress-zstd", 13UL ) ) ) {
585586
compress_websocket = 1;
586587
}
587588
}

0 commit comments

Comments
 (0)