]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
setopt_cptr: make overflow check only done when needed
authorDaniel Stenberg <daniel@haxx.se>
Tue, 29 Oct 2024 07:01:47 +0000 (08:01 +0100)
committerDaniel Stenberg <daniel@haxx.se>
Tue, 29 Oct 2024 08:25:29 +0000 (09:25 +0100)
An overflow check for if the value of a curl_off_t is larger than a
size_t can hold, is only necessary if the two types are actually
differently sized, now checked by the preprocessor. To avoid
"Unreachable Conditional".

Closes #15439

lib/setopt.c

index 84e605d5ef71fa5106f76fcb870ed2344002b18b..48642602a752ed8fc6f77c6ffbbb1d77bf3581d9 100644 (file)
@@ -1730,14 +1730,15 @@ static CURLcode setopt_cptr(struct Curl_easy *data, CURLoption option,
     if(!ptr || data->set.postfieldsize == -1)
       result = Curl_setstropt(&data->set.str[STRING_COPYPOSTFIELDS], ptr);
     else {
+      if(data->set.postfieldsize < 0)
+        return CURLE_BAD_FUNCTION_ARGUMENT;
+#if SIZEOF_CURL_OFF_T > SIZEOF_SIZE_T
       /*
        *  Check that requested length does not overflow the size_t type.
        */
-
-      if((data->set.postfieldsize < 0) ||
-         ((sizeof(curl_off_t) != sizeof(size_t)) &&
-          (data->set.postfieldsize > (curl_off_t)((size_t)-1))))
+      else if(data->set.postfieldsize > SIZE_T_MAX)
         return CURLE_OUT_OF_MEMORY;
+#endif
       else {
         /* Allocate even when size == 0. This satisfies the need of possible
            later address compare to detect the COPYPOSTFIELDS mode, and to