From 8403e5a7014ecabb306ce492ee4c54bc886159d0 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Mon, 14 Oct 2024 13:01:19 +0200 Subject: [PATCH] tests: fix callback signatures to please UndefinedBehaviorSanitizer Make test applications use the correct prototypes for callbacks. Closes #15289 --- lib/doh.c | 2 +- lib/easy.c | 15 ++++----- lib/speedcheck.h | 2 +- tests/http/clients/h2-pausing.c | 2 +- tests/http/clients/upload-pausing.c | 8 ++--- tests/libtest/lib1485.c | 4 +-- tests/libtest/lib1509.c | 8 ++--- tests/libtest/lib1540.c | 4 +-- tests/libtest/lib1541.c | 4 +-- tests/libtest/lib1556.c | 2 +- tests/libtest/lib2308.c | 2 +- tests/libtest/lib3207.c | 47 +++++++++++++++-------------- tests/libtest/lib552.c | 2 +- tests/libtest/lib571.c | 2 +- tests/libtest/lib576.c | 3 +- tests/libtest/testtrace.c | 7 ++--- tests/libtest/testtrace.h | 3 +- 17 files changed, 59 insertions(+), 58 deletions(-) diff --git a/lib/doh.c b/lib/doh.c index 8a9b023672..1873d413b7 100644 --- a/lib/doh.c +++ b/lib/doh.c @@ -180,7 +180,7 @@ UNITTEST DOHcode doh_req_encode(const char *host, } static size_t -doh_write_cb(const void *contents, size_t size, size_t nmemb, void *userp) +doh_write_cb(char *contents, size_t size, size_t nmemb, void *userp) { size_t realsize = size * nmemb; struct dynbuf *mem = (struct dynbuf *)userp; diff --git a/lib/easy.c b/lib/easy.c index 8a18023736..d16fa8c07a 100644 --- a/lib/easy.c +++ b/lib/easy.c @@ -398,9 +398,9 @@ struct events { * Callback that gets called with a new value when the timeout should be * updated. */ -static int events_timer(struct Curl_multi *multi, /* multi handle */ +static int events_timer(CURLM *multi, /* multi handle */ long timeout_ms, /* see above */ - void *userp) /* private callback pointer */ + void *userp) /* private callback pointer */ { struct events *ev = userp; (void)multi; @@ -449,7 +449,7 @@ static short socketcb2poll(int pollmask) * Callback that gets called with information about socket activity to * monitor. */ -static int events_socket(struct Curl_easy *easy, /* easy handle */ +static int events_socket(CURL *easy, /* easy handle */ curl_socket_t s, /* socket */ int what, /* see above */ void *userp, /* private callback @@ -461,6 +461,7 @@ static int events_socket(struct Curl_easy *easy, /* easy handle */ struct socketmonitor *m; struct socketmonitor *prev = NULL; bool found = FALSE; + struct Curl_easy *data = easy; #if defined(CURL_DISABLE_VERBOSE_STRINGS) (void) easy; @@ -479,13 +480,13 @@ static int events_socket(struct Curl_easy *easy, /* easy handle */ else ev->list = nxt; free(m); - infof(easy, "socket cb: socket %" FMT_SOCKET_T " REMOVED", s); + infof(data, "socket cb: socket %" FMT_SOCKET_T " REMOVED", s); } else { /* The socket 's' is already being monitored, update the activity mask. Convert from libcurl bitmask to the poll one. */ m->socket.events = socketcb2poll(what); - infof(easy, "socket cb: socket %" FMT_SOCKET_T + infof(data, "socket cb: socket %" FMT_SOCKET_T " UPDATED as %s%s", s, (what&CURL_POLL_IN) ? "IN" : "", (what&CURL_POLL_OUT) ? "OUT" : ""); @@ -499,7 +500,7 @@ static int events_socket(struct Curl_easy *easy, /* easy handle */ if(!found) { if(what == CURL_POLL_REMOVE) { /* should not happen if our logic is correct, but is no drama. */ - DEBUGF(infof(easy, "socket cb: asked to REMOVE socket %" + DEBUGF(infof(data, "socket cb: asked to REMOVE socket %" FMT_SOCKET_T "but not present!", s)); DEBUGASSERT(0); } @@ -511,7 +512,7 @@ static int events_socket(struct Curl_easy *easy, /* easy handle */ m->socket.events = socketcb2poll(what); m->socket.revents = 0; ev->list = m; - infof(easy, "socket cb: socket %" FMT_SOCKET_T " ADDED as %s%s", s, + infof(data, "socket cb: socket %" FMT_SOCKET_T " ADDED as %s%s", s, (what&CURL_POLL_IN) ? "IN" : "", (what&CURL_POLL_OUT) ? "OUT" : ""); } diff --git a/lib/speedcheck.h b/lib/speedcheck.h index bff2f32b77..8b116f1528 100644 --- a/lib/speedcheck.h +++ b/lib/speedcheck.h @@ -27,7 +27,7 @@ #include "curl_setup.h" #include "timeval.h" - +struct Curl_easy; void Curl_speedinit(struct Curl_easy *data); CURLcode Curl_speedcheck(struct Curl_easy *data, struct curltime now); diff --git a/tests/http/clients/h2-pausing.c b/tests/http/clients/h2-pausing.c index a0c111148b..1fd54d4f63 100644 --- a/tests/http/clients/h2-pausing.c +++ b/tests/http/clients/h2-pausing.c @@ -167,7 +167,7 @@ struct handle CURL *h; }; -static size_t cb(void *data, size_t size, size_t nmemb, void *clientp) +static size_t cb(char *data, size_t size, size_t nmemb, void *clientp) { size_t realsize = size * nmemb; struct handle *handle = (struct handle *) clientp; diff --git a/tests/http/clients/upload-pausing.c b/tests/http/clients/upload-pausing.c index 272d4157f4..ff68b7bd14 100644 --- a/tests/http/clients/upload-pausing.c +++ b/tests/http/clients/upload-pausing.c @@ -159,10 +159,10 @@ static size_t read_callback(char *ptr, size_t size, size_t nmemb, } static int progress_callback(void *clientp, - double dltotal, - double dlnow, - double ultotal, - double ulnow) + curl_off_t dltotal, + curl_off_t dlnow, + curl_off_t ultotal, + curl_off_t ulnow) { (void)dltotal; (void)dlnow; diff --git a/tests/libtest/lib1485.c b/tests/libtest/lib1485.c index e1710ee2f9..650746a378 100644 --- a/tests/libtest/lib1485.c +++ b/tests/libtest/lib1485.c @@ -35,7 +35,7 @@ struct transfer_status { int http_status; }; -static size_t header_callback(void *ptr, size_t size, size_t nmemb, +static size_t header_callback(char *ptr, size_t size, size_t nmemb, void *userp) { struct transfer_status *st = (struct transfer_status *)userp; @@ -77,7 +77,7 @@ static size_t header_callback(void *ptr, size_t size, size_t nmemb, return len; } -static size_t write_callback(void *ptr, size_t size, size_t nmemb, void *userp) +static size_t write_callback(char *ptr, size_t size, size_t nmemb, void *userp) { struct transfer_status *st = (struct transfer_status *)userp; size_t len = size * nmemb; diff --git a/tests/libtest/lib1509.c b/tests/libtest/lib1509.c index d60f250068..328ebd5d06 100644 --- a/tests/libtest/lib1509.c +++ b/tests/libtest/lib1509.c @@ -27,8 +27,8 @@ #include "warnless.h" #include "memdebug.h" -size_t WriteOutput(void *ptr, size_t size, size_t nmemb, void *stream); -size_t WriteHeader(void *ptr, size_t size, size_t nmemb, void *stream); +size_t WriteOutput(char *ptr, size_t size, size_t nmemb, void *stream); +size_t WriteHeader(char *ptr, size_t size, size_t nmemb, void *stream); static unsigned long realHeaderSize = 0; @@ -82,13 +82,13 @@ test_cleanup: return res; } -size_t WriteOutput(void *ptr, size_t size, size_t nmemb, void *stream) +size_t WriteOutput(char *ptr, size_t size, size_t nmemb, void *stream) { fwrite(ptr, size, nmemb, stream); return nmemb * size; } -size_t WriteHeader(void *ptr, size_t size, size_t nmemb, void *stream) +size_t WriteHeader(char *ptr, size_t size, size_t nmemb, void *stream) { (void)ptr; (void)stream; diff --git a/tests/libtest/lib1540.c b/tests/libtest/lib1540.c index 714d5d5e7c..210879447e 100644 --- a/tests/libtest/lib1540.c +++ b/tests/libtest/lib1540.c @@ -57,7 +57,7 @@ static int please_continue(void *userp, return 0; /* go on */ } -static size_t header_callback(void *ptr, size_t size, size_t nmemb, +static size_t header_callback(char *ptr, size_t size, size_t nmemb, void *userp) { size_t len = size * nmemb; @@ -66,7 +66,7 @@ static size_t header_callback(void *ptr, size_t size, size_t nmemb, return len; } -static size_t write_callback(void *ptr, size_t size, size_t nmemb, void *userp) +static size_t write_callback(char *ptr, size_t size, size_t nmemb, void *userp) { struct transfer_status *st = (struct transfer_status *)userp; size_t len = size * nmemb; diff --git a/tests/libtest/lib1541.c b/tests/libtest/lib1541.c index 640a2f1690..a60d61a7ec 100644 --- a/tests/libtest/lib1541.c +++ b/tests/libtest/lib1541.c @@ -77,7 +77,7 @@ static void check_time0(CURL *easy, int key, const char *name, report_time(name, where, tval, !tval); } -static size_t header_callback(void *ptr, size_t size, size_t nmemb, +static size_t header_callback(char *ptr, size_t size, size_t nmemb, void *userp) { struct transfer_status *st = (struct transfer_status *)userp; @@ -100,7 +100,7 @@ static size_t header_callback(void *ptr, size_t size, size_t nmemb, return len; } -static size_t write_callback(void *ptr, size_t size, size_t nmemb, void *userp) +static size_t write_callback(char *ptr, size_t size, size_t nmemb, void *userp) { struct transfer_status *st = (struct transfer_status *)userp; diff --git a/tests/libtest/lib1556.c b/tests/libtest/lib1556.c index 5b05ff0ef4..25be5e50fa 100644 --- a/tests/libtest/lib1556.c +++ b/tests/libtest/lib1556.c @@ -31,7 +31,7 @@ struct headerinfo { size_t largest; }; -static size_t header(void *ptr, size_t size, size_t nmemb, void *stream) +static size_t header(char *ptr, size_t size, size_t nmemb, void *stream) { size_t headersize = size * nmemb; struct headerinfo *info = (struct headerinfo *)stream; diff --git a/tests/libtest/lib2308.c b/tests/libtest/lib2308.c index 7751a15052..47e0763c81 100644 --- a/tests/libtest/lib2308.c +++ b/tests/libtest/lib2308.c @@ -27,7 +27,7 @@ #include -static size_t cb_curl(void *buffer, size_t size, size_t nmemb, void *userp) +static size_t cb_curl(char *buffer, size_t size, size_t nmemb, void *userp) { (void)buffer; (void)size; diff --git a/tests/libtest/lib3207.c b/tests/libtest/lib3207.c index 6c819b3596..a78608156d 100644 --- a/tests/libtest/lib3207.c +++ b/tests/libtest/lib3207.c @@ -46,29 +46,30 @@ struct Ctx { struct curl_slist *contents; }; -static size_t write_memory_callback(void *contents, size_t size, - size_t nmemb, void *userp) { - /* append the data to contents */ - size_t realsize = size * nmemb; - struct Ctx *mem = (struct Ctx *)userp; - char *data = (char *)malloc(realsize + 1); - struct curl_slist *item_append = NULL; - if(!data) { - printf("not enough memory (malloc returned NULL)\n"); - return 0; - } - memcpy(data, contents, realsize); - data[realsize] = '\0'; - item_append = curl_slist_append(mem->contents, data); - free(data); - if(item_append) { - mem->contents = item_append; - } - else { - printf("not enough memory (curl_slist_append returned NULL)\n"); - return 0; - } - return realsize; +static size_t write_memory_callback(char *contents, size_t size, + size_t nmemb, void *userp) +{ + /* append the data to contents */ + size_t realsize = size * nmemb; + struct Ctx *mem = (struct Ctx *)userp; + char *data = (char *)malloc(realsize + 1); + struct curl_slist *item_append = NULL; + if(!data) { + printf("not enough memory (malloc returned NULL)\n"); + return 0; + } + memcpy(data, contents, realsize); + data[realsize] = '\0'; + item_append = curl_slist_append(mem->contents, data); + free(data); + if(item_append) { + mem->contents = item_append; + } + else { + printf("not enough memory (curl_slist_append returned NULL)\n"); + return 0; + } + return realsize; } static diff --git a/tests/libtest/lib552.c b/tests/libtest/lib552.c index 76244ab339..0920b025a8 100644 --- a/tests/libtest/lib552.c +++ b/tests/libtest/lib552.c @@ -141,7 +141,7 @@ static size_t read_callback(char *ptr, size_t size, size_t nmemb, void *stream) } -static size_t write_callback(void *ptr, size_t size, size_t nmemb, +static size_t write_callback(char *ptr, size_t size, size_t nmemb, void *stream) { int amount = curlx_uztosi(size * nmemb); diff --git a/tests/libtest/lib571.c b/tests/libtest/lib571.c index 6579889995..b7868e0a32 100644 --- a/tests/libtest/lib571.c +++ b/tests/libtest/lib571.c @@ -52,7 +52,7 @@ static const char *RTP_DATA = "$_1234\n\0Rsdf"; static int rtp_packet_count = 0; -static size_t rtp_write(void *ptr, size_t size, size_t nmemb, void *stream) +static size_t rtp_write(char *ptr, size_t size, size_t nmemb, void *stream) { char *data = (char *)ptr; int channel = RTP_PKT_CHANNEL(data); diff --git a/tests/libtest/lib576.c b/tests/libtest/lib576.c index 784f22d3f3..db5a41aad6 100644 --- a/tests/libtest/lib576.c +++ b/tests/libtest/lib576.c @@ -32,8 +32,9 @@ struct chunk_data { }; static -long chunk_bgn(const struct curl_fileinfo *finfo, void *ptr, int remains) +long chunk_bgn(const void *f, void *ptr, int remains) { + const struct curl_fileinfo *finfo = f; struct chunk_data *ch_d = ptr; ch_d->remains = remains; diff --git a/tests/libtest/testtrace.c b/tests/libtest/testtrace.c index 49ff8ae20e..fd4cb5bb47 100644 --- a/tests/libtest/testtrace.c +++ b/tests/libtest/testtrace.c @@ -85,10 +85,8 @@ void libtest_debug_dump(const char *timebuf, const char *text, FILE *stream, } int libtest_debug_cb(CURL *handle, curl_infotype type, - unsigned char *data, size_t size, - void *userp) + char *data, size_t size, void *userp) { - struct libtest_trace_cfg *trace_cfg = userp; const char *text; struct timeval tv; @@ -140,6 +138,7 @@ int libtest_debug_cb(CURL *handle, curl_infotype type, return 0; } - libtest_debug_dump(timebuf, text, stderr, data, size, trace_cfg->nohex); + libtest_debug_dump(timebuf, text, stderr, (unsigned char *)data, size, + trace_cfg->nohex); return 0; } diff --git a/tests/libtest/testtrace.h b/tests/libtest/testtrace.h index 35f27b0965..d7087c5366 100644 --- a/tests/libtest/testtrace.h +++ b/tests/libtest/testtrace.h @@ -32,7 +32,6 @@ struct libtest_trace_cfg { extern struct libtest_trace_cfg libtest_debug_config; int libtest_debug_cb(CURL *handle, curl_infotype type, - unsigned char *data, size_t size, - void *userp); + char *data, size_t size, void *userp); #endif /* HEADER_LIBTEST_TESTTRACE_H */ -- 2.47.3