]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
lib: parse numbers with fixed known base 10
authorDaniel Stenberg <daniel@haxx.se>
Thu, 17 Nov 2022 07:41:44 +0000 (08:41 +0100)
committerDaniel Stenberg <daniel@haxx.se>
Thu, 17 Nov 2022 22:15:37 +0000 (23:15 +0100)
... instead of using 0 argument that allows decimal, hex or octal when
the number is documented and assumed to use base 10.

Closes #9933

lib/curl_range.c
lib/ftp.c
lib/strtoofft.c
lib/vssh/libssh.c
lib/vssh/libssh2.c
src/tool_getparam.c
src/tool_paramhlp.c

index dd92d05b39c04f52d7ca8ede253d977038bef0e5..49999367d72b821e408ab2dfefddbfb09c4bf100 100644 (file)
@@ -44,12 +44,12 @@ CURLcode Curl_range(struct Curl_easy *data)
   if(data->state.use_range && data->state.range) {
     CURLofft from_t;
     CURLofft to_t;
-    from_t = curlx_strtoofft(data->state.range, &ptr, 0, &from);
+    from_t = curlx_strtoofft(data->state.range, &ptr, 10, &from);
     if(from_t == CURL_OFFT_FLOW)
       return CURLE_RANGE_ERROR;
     while(*ptr && (ISBLANK(*ptr) || (*ptr == '-')))
       ptr++;
-    to_t = curlx_strtoofft(ptr, &ptr2, 0, &to);
+    to_t = curlx_strtoofft(ptr, &ptr2, 10, &to);
     if(to_t == CURL_OFFT_FLOW)
       return CURLE_RANGE_ERROR;
     if((to_t == CURL_OFFT_INVAL) && !from_t) {
index 2c639ebff449cecd6c5e20e8af5b79b6ad552831..4f7c12faa895b99ee6e1b6fb804cf50e2fee3b8f 100644 (file)
--- a/lib/ftp.c
+++ b/lib/ftp.c
@@ -2299,7 +2299,7 @@ static CURLcode ftp_state_size_resp(struct Curl_easy *data,
     else
       fdigit = start;
     /* ignores parsing errors, which will make the size remain unknown */
-    (void)curlx_strtoofft(fdigit, NULL, 0, &filesize);
+    (void)curlx_strtoofft(fdigit, NULL, 10, &filesize);
 
   }
   else if(ftpcode == 550) { /* "No such file or directory" */
@@ -2484,7 +2484,7 @@ static CURLcode ftp_state_get_resp(struct Curl_easy *data,
         if(bytes) {
           ++bytes;
           /* get the number! */
-          (void)curlx_strtoofft(bytes, NULL, 0, &size);
+          (void)curlx_strtoofft(bytes, NULL, 10, &size);
         }
       }
     }
index 30deb8c05b290b2581555877a045736fac719b7c..fb8d92196f61a55827895f5b0a23009e7c507e53 100644 (file)
@@ -221,6 +221,7 @@ CURLofft curlx_strtoofft(const char *str, char **endp, int base,
   curl_off_t number;
   errno = 0;
   *num = 0; /* clear by default */
+  DEBUGASSERT(base); /* starting now, avoid base zero */
 
   while(*str && ISBLANK(*str))
     str++;
index df644416826fdbb5d36d764e8c20e708961c1e95..0869c483cb168e7b1cd55a90479024e51f1f8f40 100644 (file)
@@ -1663,13 +1663,13 @@ static CURLcode myssh_statemach_act(struct Curl_easy *data, bool *block)
           CURLofft to_t;
           CURLofft from_t;
 
-          from_t = curlx_strtoofft(data->state.range, &ptr, 0, &from);
+          from_t = curlx_strtoofft(data->state.range, &ptr, 10, &from);
           if(from_t == CURL_OFFT_FLOW) {
             return CURLE_RANGE_ERROR;
           }
           while(*ptr && (ISBLANK(*ptr) || (*ptr == '-')))
             ptr++;
-          to_t = curlx_strtoofft(ptr, &ptr2, 0, &to);
+          to_t = curlx_strtoofft(ptr, &ptr2, 10, &to);
           if(to_t == CURL_OFFT_FLOW) {
             return CURLE_RANGE_ERROR;
           }
index 2211213e3011a81a824731514f45fefb643abcbf..338062366bfef85a96b4b93435f8bde0b57485a4 100644 (file)
@@ -2503,12 +2503,12 @@ static CURLcode ssh_statemach_act(struct Curl_easy *data, bool *block)
           CURLofft to_t;
           CURLofft from_t;
 
-          from_t = curlx_strtoofft(data->state.range, &ptr, 0, &from);
+          from_t = curlx_strtoofft(data->state.range, &ptr, 10, &from);
           if(from_t == CURL_OFFT_FLOW)
             return CURLE_RANGE_ERROR;
           while(*ptr && (ISBLANK(*ptr) || (*ptr == '-')))
             ptr++;
-          to_t = curlx_strtoofft(ptr, &ptr2, 0, &to);
+          to_t = curlx_strtoofft(ptr, &ptr2, 10, &to);
           if(to_t == CURL_OFFT_FLOW)
             return CURLE_RANGE_ERROR;
           if((to_t == CURL_OFFT_INVAL) /* no "to" value given */
index d899a9263b35255fe01e2b32a32129713a1a0e50..0beb94572c3b9e17e2d18c62942ad73c6e4968d0 100644 (file)
@@ -502,7 +502,7 @@ static ParameterError GetSizeParameter(struct GlobalConfig *global,
   char *unit;
   curl_off_t value;
 
-  if(curlx_strtoofft(arg, &unit, 0, &value)) {
+  if(curlx_strtoofft(arg, &unit, 10, &value)) {
     warnf(global, "invalid number specified for %s\n", which);
     return PARAM_BAD_USE;
   }
index acf34ac24dd91b1bfca497a1a690269f2b5a8143..ae9fb1377a4d92297217b9fbf3baf0eedc6bc9d0 100644 (file)
@@ -473,7 +473,7 @@ ParameterError str2offset(curl_off_t *val, const char *str)
 
 #if(SIZEOF_CURL_OFF_T > SIZEOF_LONG)
   {
-    CURLofft offt = curlx_strtoofft(str, &endptr, 0, val);
+    CURLofft offt = curlx_strtoofft(str, &endptr, 10, val);
     if(CURL_OFFT_FLOW == offt)
       return PARAM_NUMBER_TOO_LARGE;
     else if(CURL_OFFT_INVAL == offt)