src/server/util/io.c

changeset 688
02360295ec58
parent 687
4bded456b4a7
--- a/src/server/util/io.c	Thu Feb 19 18:34:36 2026 +0100
+++ b/src/server/util/io.c	Fri Feb 20 13:57:40 2026 +0100
@@ -629,6 +629,7 @@
 int http_stream_parse_chunk_header(char *str, int len, WSBool first, int64_t *chunklen) {
     char *hdr_start = NULL;
     char *hdr_end = NULL;
+    char *chk_end = str + len;
     int i = 0;
     if(first) {
         hdr_start = str;
@@ -660,6 +661,10 @@
        
     if(*hdr_end == '\r') {
         // we also need '\n'
+        if(hdr_end + 1 >= chk_end) {
+            return 0; // incomplete
+        }
+        
         if(hdr_end[1] != '\n') {
             return -1;
         }
@@ -717,7 +722,7 @@
     }
     
     char *rbuf = buf; // buffer pos
-    size_t rd = 0; // number of bytes read
+    ssize_t rd = 0; // number of bytes read
     size_t rbuflen = nbytes; // number of bytes until end of buf
     WSBool perform_io = WS_TRUE; // we do only 1 read before we abort
     while(rd < nbytes && (perform_io || (st->max_read - st->read) > 0)) {

mercurial