]> granicus.if.org Git - curl/commitdiff
http2: get rid of another strstr()
authorDaniel Stenberg <daniel@haxx.se>
Thu, 26 Apr 2018 08:41:21 +0000 (10:41 +0200)
committerDaniel Stenberg <daniel@haxx.se>
Thu, 26 Apr 2018 12:55:26 +0000 (14:55 +0200)
Follow-up to 1514c44655e12e: replace another strstr() call done on a
buffer that might not be zero terminated - with a memchr() call, even if
we know the substring will be found.

Assisted-by: Max Dymond
Detected by OSS-Fuzz
Bug: https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=8021

Closes #2534

lib/http2.c

index 7dea16125e7ba23f369546ea012afdea370f3df0..25d74c1a123aab73579d46783a6601ba16414808 100644 (file)
@@ -1923,8 +1923,10 @@ static ssize_t http2_send(struct connectdata *conn, int sockindex,
 
     hdbuf = line_end + 2;
 
-    line_end = strstr(hdbuf, "\r\n");
-    if(line_end == hdbuf)
+    /* check for next CR, but only within the piece of data left in the given
+       buffer */
+    line_end = memchr(hdbuf, '\r', len - (hdbuf - (char *)mem));
+    if(!line_end || (line_end == hdbuf))
       goto fail;
 
     /* header continuation lines are not supported */