mirror of
https://github.com/curl/curl.git
synced 2024-12-15 06:40:09 +08:00
setopt: do bounds-check before strdup
Curl_setstropt() allocated memory for the string before checking if the string was within bounds. The bounds check should be done first. Closes #8377
This commit is contained in:
parent
2cd6d7e462
commit
a121e8dac6
15
lib/setopt.c
15
lib/setopt.c
@ -62,19 +62,12 @@ CURLcode Curl_setstropt(char **charp, const char *s)
|
||||
Curl_safefree(*charp);
|
||||
|
||||
if(s) {
|
||||
char *str = strdup(s);
|
||||
if(strlen(s) > CURL_MAX_INPUT_LENGTH)
|
||||
return CURLE_BAD_FUNCTION_ARGUMENT;
|
||||
|
||||
if(str) {
|
||||
size_t len = strlen(str);
|
||||
if(len > CURL_MAX_INPUT_LENGTH) {
|
||||
free(str);
|
||||
return CURLE_BAD_FUNCTION_ARGUMENT;
|
||||
}
|
||||
}
|
||||
if(!str)
|
||||
*charp = strdup(s);
|
||||
if(!*charp)
|
||||
return CURLE_OUT_OF_MEMORY;
|
||||
|
||||
*charp = str;
|
||||
}
|
||||
|
||||
return CURLE_OK;
|
||||
|
Loading…
Reference in New Issue
Block a user