]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
lib: add debug log outputs for CURLE_BAD_FUNCTION_ARGUMENT
authorDaniel Stenberg <daniel@haxx.se>
Mon, 8 Jan 2024 09:34:06 +0000 (10:34 +0100)
committerDaniel Stenberg <daniel@haxx.se>
Mon, 8 Jan 2024 21:48:24 +0000 (22:48 +0100)
Closes #12658

13 files changed:
lib/altsvc.c
lib/asyn-ares.c
lib/easy.c
lib/headers.c
lib/hsts.c
lib/http.c
lib/krb5.c
lib/mime.c
lib/mqtt.c
lib/rand.c
lib/setopt.c
lib/telnet.c
lib/ws.c

index b5fb65fde1dff4f31621b8606760afde71206b60..e9f62bf0e0a511c2c618054635941f8a7602dbbe 100644 (file)
@@ -335,9 +335,6 @@ CURLcode Curl_altsvc_load(struct altsvcinfo *asi, const char *file)
 CURLcode Curl_altsvc_ctrl(struct altsvcinfo *asi, const long ctrl)
 {
   DEBUGASSERT(asi);
-  if(!ctrl)
-    /* unexpected */
-    return CURLE_BAD_FUNCTION_ARGUMENT;
   asi->flags = ctrl;
   return CURLE_OK;
 }
index c3030154b3eb51ae43dd3b2b2922d5c8aafa06f6..f1ff49277c491ee3edc46969e01e5857ff456804 100644 (file)
@@ -858,6 +858,7 @@ CURLcode Curl_set_dns_servers(struct Curl_easy *data,
   case ARES_ENODATA:
   case ARES_EBADSTR:
   default:
+    DEBUGF(infof(data, "bad servers set"));
     result = CURLE_BAD_FUNCTION_ARGUMENT;
     break;
   }
@@ -896,6 +897,7 @@ CURLcode Curl_set_dns_local_ip4(struct Curl_easy *data,
   }
   else {
     if(Curl_inet_pton(AF_INET, local_ip4, &a4) != 1) {
+      DEBUGF(infof(data, "bad DNS IPv4 address"));
       return CURLE_BAD_FUNCTION_ARGUMENT;
     }
   }
@@ -923,6 +925,7 @@ CURLcode Curl_set_dns_local_ip6(struct Curl_easy *data,
   }
   else {
     if(Curl_inet_pton(AF_INET6, local_ip6, a6) != 1) {
+      DEBUGF(infof(data, "bad DNS IPv6 address"));
       return CURLE_BAD_FUNCTION_ARGUMENT;
     }
   }
index 085f368c9bebe59dd0946877ccf49fb8c8915da6..067b6d7b69f5fd855ac4b154cb93a63c20662ea2 100644 (file)
@@ -688,9 +688,9 @@ static CURLcode easy_transfer(struct Curl_multi *multi)
   /* Make sure to return some kind of error if there was a multi problem */
   if(mcode) {
     result = (mcode == CURLM_OUT_OF_MEMORY) ? CURLE_OUT_OF_MEMORY :
-              /* The other multi errors should never happen, so return
-                 something suitably generic */
-              CURLE_BAD_FUNCTION_ARGUMENT;
+      /* The other multi errors should never happen, so return
+         something suitably generic */
+      CURLE_BAD_FUNCTION_ARGUMENT;
   }
 
   return result;
index 3ff4d5eb07399b7e4434c338b976e5226efe49c1..b6fcdda777cfdf34544b3ec30d29672c21dd19f7 100644 (file)
@@ -185,7 +185,7 @@ struct curl_header *curl_easy_nextheader(CURL *easy,
 }
 
 static CURLcode namevalue(char *header, size_t hlen, unsigned int type,
-                           char **name, char **value)
+                          char **name, char **value)
 {
   char *end = header + hlen - 1; /* point to the last byte */
   DEBUGASSERT(hlen);
@@ -291,6 +291,7 @@ CURLcode Curl_headers_push(struct Curl_easy *data, const char *header,
   end = strchr(header, '\r');
   if(!end) {
     end = strchr(header, '\n');
+    DEBUGASSERT(end);
     if(!end)
       return CURLE_BAD_FUNCTION_ARGUMENT;
   }
index 99f5bd458fe5747679a7f01ce889ebb474d2e333..5677e4f3d124928ff23a5048bfa57ce7c033f46a 100644 (file)
@@ -127,6 +127,7 @@ static CURLcode hsts_create(struct hsts *h,
   if(hlen && (hostname[hlen - 1] == '.'))
     /* strip off any trailing dot */
     --hlen;
+  DEBUGASSERT(hlen);
   if(!hlen)
     /* no host name left */
     return CURLE_BAD_FUNCTION_ARGUMENT;
@@ -481,6 +482,7 @@ static CURLcode hsts_pull(struct Curl_easy *data, struct hsts *h)
       if(sc == CURLSTS_OK) {
         time_t expires;
         CURLcode result;
+        DEBUGASSERT(e.name[0]);
         if(!e.name[0])
           /* bail out if no name was stored */
           return CURLE_BAD_FUNCTION_ARGUMENT;
index 5b8f3e54b01f212c4203c5c9319be6e50b48cfa2..1f33c143faec80b246e4b45ead3fe8c3a9f5c3fa 100644 (file)
@@ -2095,6 +2095,7 @@ CURLcode Curl_add_timecondition(struct Curl_easy *data,
 
   switch(data->set.timecondition) {
   default:
+    DEBUGF(infof(data, "invalid time condition"));
     return CURLE_BAD_FUNCTION_ARGUMENT;
 
   case CURL_TIMECOND_IFMODSINCE:
index 91f8a1077f760689b7ab75f3c15d97eac38b0b1a..19f0f0cf106aa2a4ac0491dafadaf869586f11c6 100644 (file)
@@ -75,8 +75,7 @@ static CURLcode ftpsend(struct Curl_easy *data, struct connectdata *conn,
   unsigned char data_sec = conn->data_prot;
 #endif
 
-  if(!cmd)
-    return CURLE_BAD_FUNCTION_ARGUMENT;
+  DEBUGASSERT(cmd);
 
   write_len = strlen(cmd);
   if(!write_len || write_len > (sizeof(s) -3))
index d61cbeb8294b46d9ceff4348b45d66d9fdcec819..e6553816fa3a5773e53a33fb8d50c4f498d7f1b4 100644 (file)
@@ -1236,6 +1236,7 @@ CURLcode Curl_mime_duppart(struct Curl_easy *data,
     }
     break;
   default:  /* Invalid kind: should not occur. */
+    DEBUGF(infof(data, "invalid MIMEKIND* attempt"));
     res = CURLE_BAD_FUNCTION_ARGUMENT;  /* Internal error? */
     break;
   }
index b304bd6297477ccff9bd9f0023743ad9b01f33fb..e3a7aff9791868955878c2d32304f317632c0a06 100644 (file)
@@ -524,8 +524,10 @@ static CURLcode mqtt_publish(struct Curl_easy *data)
   char encodedbytes[4];
   curl_off_t postfieldsize = data->set.postfieldsize;
 
-  if(!payload)
+  if(!payload) {
+    DEBUGF(infof(data, "mqtt_publish without payload, return bad arg"));
     return CURLE_BAD_FUNCTION_ARGUMENT;
+  }
   if(postfieldsize < 0)
     payloadlen = strlen(payload);
   else
index 3383c490b67b0083fcb7f5f8d21aa4c95a51ba59..c62b1a40323f5fc8005d0089b2397ef74dcbcb3a 100644 (file)
@@ -201,7 +201,7 @@ CURLcode Curl_rand(struct Curl_easy *data, unsigned char *rnd, size_t num)
 {
   CURLcode result = CURLE_BAD_FUNCTION_ARGUMENT;
 
-  DEBUGASSERT(num > 0);
+  DEBUGASSERT(num);
 
   while(num) {
     unsigned int r;
@@ -241,9 +241,11 @@ CURLcode Curl_rand_hex(struct Curl_easy *data, unsigned char *rnd,
   memset(buffer, 0, sizeof(buffer));
 #endif
 
-  if((num/2 >= sizeof(buffer)) || !(num&1))
+  if((num/2 >= sizeof(buffer)) || !(num&1)) {
     /* make sure it fits in the local buffer and that it is an odd number! */
+    DEBUGF(infof(data, "invalid buffer size with Curl_rand_hex"));
     return CURLE_BAD_FUNCTION_ARGUMENT;
+  }
 
   num--; /* save one for null-termination */
 
index e13432334d9a04261d81922155b0819d30643057..72bd6cdf6f65b968cf310aba027b270c8cb84248 100644 (file)
@@ -3122,6 +3122,10 @@ CURLcode Curl_vsetopt(struct Curl_easy *data, CURLoption option, va_list param)
         return CURLE_OUT_OF_MEMORY;
     }
     arg = va_arg(param, long);
+    if(!arg) {
+      DEBUGF(infof(data, "bad CURLOPT_ALTSVC_CTRL input"));
+      return CURLE_BAD_FUNCTION_ARGUMENT;
+    }
     result = Curl_altsvc_ctrl(data->asi, arg);
     if(result)
       return result;
@@ -3176,5 +3180,9 @@ CURLcode curl_easy_setopt(struct Curl_easy *data, CURLoption tag, ...)
   result = Curl_vsetopt(data, tag, arg);
 
   va_end(arg);
+#ifdef DEBUGBUILD
+  if(result == CURLE_BAD_FUNCTION_ARGUMENT)
+    infof(data, "setopt arg 0x%x returned CURLE_BAD_FUNCTION_ARGUMENT", tag);
+#endif
   return result;
 }
index 1a1171ccb7206161270531e87b655386e75708b1..67667e347e581d61177e4acb05b9418a9f6857a6 100644 (file)
@@ -799,8 +799,10 @@ static CURLcode check_telnet_options(struct Curl_easy *data)
      was given on the command line */
   if(data->state.aptr.user) {
     char buffer[256];
-    if(str_is_nonascii(data->conn->user))
+    if(str_is_nonascii(data->conn->user)) {
+      DEBUGF(infof(data, "set a non ASCII user name in telnet"));
       return CURLE_BAD_FUNCTION_ARGUMENT;
+    }
     msnprintf(buffer, sizeof(buffer), "USER,%s", data->conn->user);
     beg = curl_slist_append(tn->telnet_vars, buffer);
     if(!beg) {
index f924362a865820ea87f2315233f7757d528f6a3b..81b48180ccfed144ed09a45b169ece3ef321c08f 100644 (file)
--- a/lib/ws.c
+++ b/lib/ws.c
@@ -997,8 +997,11 @@ CURL_EXTERN CURLcode curl_ws_send(CURL *data, const void *buffer,
   ws = data->conn->proto.ws;
 
   if(data->set.ws_raw_mode) {
-    if(fragsize || flags)
+    if(fragsize || flags) {
+      DEBUGF(infof(data, "ws_send: "
+                   "fragsize and flags cannot be non-zero in raw mode"));
       return CURLE_BAD_FUNCTION_ARGUMENT;
+    }
     if(!buflen)
       /* nothing to do */
       return CURLE_OK;