]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
setopt: Address undefined behaviour by checking for null
authorJames Keast <jkeast@blackberry.com>
Fri, 10 Feb 2023 19:24:15 +0000 (15:24 -0400)
committerDan Fandrich <dan@coneharvesters.com>
Sat, 11 Feb 2023 18:13:38 +0000 (10:13 -0800)
This addresses undefined behaviour found using clang's UBsan:

curl/lib/setopt.c:177:14: runtime error: applying non-zero offset 1 to null pointer
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior curl/lib/setopt.c:177:14 in

Closes #10472

lib/setopt.c

index b8c639847a21ba6ea5d9437a8e5b4715499dafc5..b8fa1b89e6df036e6e099012a524685b5b11a2fb 100644 (file)
@@ -174,7 +174,7 @@ static CURLcode protocol2num(const char *str, curl_prot_t *val)
 
       *val |= h->protocol;
     }
-  } while(str++);
+  } while(str && str++);
 
   if(!*val)
     /* no protocol listed */