]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
connect: fix wrong format specifier in connect error string
authorJay Satiro <raysatiro@yahoo.com>
Mon, 19 Jul 2021 23:06:30 +0000 (19:06 -0400)
committerJay Satiro <raysatiro@yahoo.com>
Tue, 20 Jul 2021 06:16:53 +0000 (02:16 -0400)
0842175 (not in any release) used the wrong format specifier (long int)
for timediff_t. On an OS such as Windows libcurl's timediff_t (usually
64-bit) is bigger than long int (32-bit). In 32-bit Windows builds the
upper 32-bits of the timediff_t were erroneously then used by the next
format specifier. Usually since the timeout isn't larger than 32-bits
this would result in null as a pointer to the string with the reason for
the connection failing. On other OSes or maybe other compilers it could
probably result in garbage values (ie crash on deref).

Before:
Failed to connect to localhost port 12345 after 1201 ms: (nil)

After:
Failed to connect to localhost port 12345 after 1203 ms: Connection refused

Closes https://github.com/curl/curl/pull/7449

lib/connect.c

index b8fde5580d60cf86f858fa5ff13c6a6bf404e4cf..11e6b888b78c4f75ab00258cbe480586677d0e04 100644 (file)
@@ -1038,7 +1038,8 @@ CURLcode Curl_is_connected(struct Curl_easy *data,
     else
       hostname = conn->host.name;
 
-    failf(data, "Failed to connect to %s port %u after %ld ms: %s",
+    failf(data, "Failed to connect to %s port %u after "
+                "%" CURL_FORMAT_TIMEDIFF_T " ms: %s",
         hostname, conn->port,
         Curl_timediff(now, data->progress.t_startsingle),
         Curl_strerror(error, buffer, sizeof(buffer)));