]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
setopt: check CURLOPT_TFTP_BLKSIZE range on set
authorDaniel Stenberg <daniel@haxx.se>
Tue, 21 Nov 2023 16:34:30 +0000 (17:34 +0100)
committerDaniel Stenberg <daniel@haxx.se>
Wed, 22 Nov 2023 06:44:05 +0000 (07:44 +0100)
... instead of later when the transfer is about to happen.

Closes #12374

lib/setopt.c
lib/tftp.c
lib/tftp.h

index 72eb2a110db76730903325d2eaa204982ff3dcd7..04762b0ebc877ac8bdb71fbc4e295fbe1a905330 100644 (file)
@@ -50,6 +50,7 @@
 #include "multiif.h"
 #include "altsvc.h"
 #include "hsts.h"
+#include "tftp.h"
 
 /* The last 3 #include files should be in this order */
 #include "curl_printf.h"
@@ -379,7 +380,7 @@ CURLcode Curl_vsetopt(struct Curl_easy *data, CURLoption option, va_list param)
      * TFTP option that specifies the block size to use for data transmission.
      */
     arg = va_arg(param, long);
-    if(arg < 0)
+    if(arg > TFTP_BLKSIZE_MAX || arg < TFTP_BLKSIZE_MIN)
       return CURLE_BAD_FUNCTION_ARGUMENT;
     data->set.tftp_blksize = arg;
     break;
index 33281356ae287d831a65882c817b5bd9ace0d6c7..663015502d71a2f07146f0dfad3b44f221f8a8a0 100644 (file)
@@ -70,8 +70,6 @@
 
 /* RFC2348 allows the block size to be negotiated */
 #define TFTP_BLKSIZE_DEFAULT 512
-#define TFTP_BLKSIZE_MIN 8
-#define TFTP_BLKSIZE_MAX 65464
 #define TFTP_OPTION_BLKSIZE "blksize"
 
 /* from RFC2349: */
@@ -978,11 +976,9 @@ static CURLcode tftp_connect(struct Curl_easy *data, bool *done)
     return CURLE_OUT_OF_MEMORY;
 
   /* alloc pkt buffers based on specified blksize */
-  if(data->set.tftp_blksize) {
+  if(data->set.tftp_blksize)
+    /* range checked when set */
     blksize = (int)data->set.tftp_blksize;
-    if(blksize > TFTP_BLKSIZE_MAX || blksize < TFTP_BLKSIZE_MIN)
-      return CURLE_TFTP_ILLEGAL;
-  }
 
   need_blksize = blksize;
   /* default size is the fallback when no OACK is received */
index 5d2d5da6151b9de03e07b6591e483b0b5dd3b27a..12404bf6d20d1be96fa35bd670af522171b0f334 100644 (file)
@@ -25,6 +25,9 @@
  ***************************************************************************/
 #ifndef CURL_DISABLE_TFTP
 extern const struct Curl_handler Curl_handler_tftp;
+
+#define TFTP_BLKSIZE_MIN 8
+#define TFTP_BLKSIZE_MAX 65464
 #endif
 
 #endif /* HEADER_CURL_TFTP_H */