From cfe7902111ae5478738c7ace8086db74963b87c6 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Mon, 8 Jan 2024 10:34:06 +0100 Subject: [PATCH] lib: add debug log outputs for CURLE_BAD_FUNCTION_ARGUMENT Closes #12658 --- lib/altsvc.c | 3 --- lib/asyn-ares.c | 3 +++ lib/easy.c | 6 +++--- lib/headers.c | 3 ++- lib/hsts.c | 2 ++ lib/http.c | 1 + lib/krb5.c | 3 +-- lib/mime.c | 1 + lib/mqtt.c | 4 +++- lib/rand.c | 6 ++++-- lib/setopt.c | 8 ++++++++ lib/telnet.c | 4 +++- lib/ws.c | 5 ++++- 13 files changed, 35 insertions(+), 14 deletions(-) diff --git a/lib/altsvc.c b/lib/altsvc.c index b5fb65fde1..e9f62bf0e0 100644 --- a/lib/altsvc.c +++ b/lib/altsvc.c @@ -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; } diff --git a/lib/asyn-ares.c b/lib/asyn-ares.c index c3030154b3..f1ff49277c 100644 --- a/lib/asyn-ares.c +++ b/lib/asyn-ares.c @@ -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; } } diff --git a/lib/easy.c b/lib/easy.c index 085f368c9b..067b6d7b69 100644 --- a/lib/easy.c +++ b/lib/easy.c @@ -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; diff --git a/lib/headers.c b/lib/headers.c index 3ff4d5eb07..b6fcdda777 100644 --- a/lib/headers.c +++ b/lib/headers.c @@ -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; } diff --git a/lib/hsts.c b/lib/hsts.c index 99f5bd458f..5677e4f3d1 100644 --- a/lib/hsts.c +++ b/lib/hsts.c @@ -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; diff --git a/lib/http.c b/lib/http.c index 5b8f3e54b0..1f33c143fa 100644 --- a/lib/http.c +++ b/lib/http.c @@ -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: diff --git a/lib/krb5.c b/lib/krb5.c index 91f8a1077f..19f0f0cf10 100644 --- a/lib/krb5.c +++ b/lib/krb5.c @@ -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)) diff --git a/lib/mime.c b/lib/mime.c index d61cbeb829..e6553816fa 100644 --- a/lib/mime.c +++ b/lib/mime.c @@ -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; } diff --git a/lib/mqtt.c b/lib/mqtt.c index b304bd6297..e3a7aff979 100644 --- a/lib/mqtt.c +++ b/lib/mqtt.c @@ -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 diff --git a/lib/rand.c b/lib/rand.c index 3383c490b6..c62b1a4032 100644 --- a/lib/rand.c +++ b/lib/rand.c @@ -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 */ diff --git a/lib/setopt.c b/lib/setopt.c index e13432334d..72bd6cdf6f 100644 --- a/lib/setopt.c +++ b/lib/setopt.c @@ -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; } diff --git a/lib/telnet.c b/lib/telnet.c index 1a1171ccb7..67667e347e 100644 --- a/lib/telnet.c +++ b/lib/telnet.c @@ -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) { diff --git a/lib/ws.c b/lib/ws.c index f924362a86..81b48180cc 100644 --- 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; -- 2.47.3