Skip to content

Commit 3f3bea5

Browse files
peffdscho
authored andcommitted
curl: fix integer constant typechecks with curl_easy_setopt()
The curl documentation specifies that curl_easy_setopt() takes either: ...a long, a function pointer, an object pointer or a curl_off_t, depending on what the specific option expects. But when we pass an integer constant like "0", it will by default be a regular non-long int. This has always been wrong, but seemed to work in practice (I didn't dig into curl's implementation to see whether this might actually be triggering undefined behavior, but it seems likely and regardless we should do what the docs say). This is especially important since curl has a type-checking macro that causes building against curl 8.14 to produce many warnings. The specific commit is due to their 79b4e56b3 (typecheck-gcc.h: fix the typechecks, 2025-04-22). Curiously, it does only seem to trigger when compiled with -O2 for me. We can fix it by just marking the constants with a long "L". Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 36a139e commit 3f3bea5

File tree

3 files changed

+11
-11
lines changed

3 files changed

+11
-11
lines changed

http-push.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ static char *xml_entities(const char *s)
194194
static void curl_setup_http_get(CURL *curl, const char *url,
195195
const char *custom_req)
196196
{
197-
curl_easy_setopt(curl, CURLOPT_HTTPGET, 1);
197+
curl_easy_setopt(curl, CURLOPT_HTTPGET, 1L);
198198
curl_easy_setopt(curl, CURLOPT_URL, url);
199199
curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, custom_req);
200200
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, fwrite_null);

http.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -744,7 +744,7 @@ static int has_proxy_cert_password(void)
744744
#ifdef GITCURL_HAVE_CURLOPT_TCP_KEEPALIVE
745745
static void set_curl_keepalive(CURL *c)
746746
{
747-
curl_easy_setopt(c, CURLOPT_TCP_KEEPALIVE, 1);
747+
curl_easy_setopt(c, CURLOPT_TCP_KEEPALIVE, 1L);
748748
}
749749

750750
#else
@@ -1071,13 +1071,13 @@ static CURL *get_curl_handle(void)
10711071
die("curl_easy_init failed");
10721072

10731073
if (!curl_ssl_verify) {
1074-
curl_easy_setopt(result, CURLOPT_SSL_VERIFYPEER, 0);
1075-
curl_easy_setopt(result, CURLOPT_SSL_VERIFYHOST, 0);
1074+
curl_easy_setopt(result, CURLOPT_SSL_VERIFYPEER, 0L);
1075+
curl_easy_setopt(result, CURLOPT_SSL_VERIFYHOST, 0L);
10761076
} else {
10771077
/* Verify authenticity of the peer's certificate */
1078-
curl_easy_setopt(result, CURLOPT_SSL_VERIFYPEER, 1);
1078+
curl_easy_setopt(result, CURLOPT_SSL_VERIFYPEER, 1L);
10791079
/* The name in the cert must match whom we tried to connect */
1080-
curl_easy_setopt(result, CURLOPT_SSL_VERIFYHOST, 2);
1080+
curl_easy_setopt(result, CURLOPT_SSL_VERIFYHOST, 2L);
10811081
}
10821082

10831083
#ifdef GIT_CURL_HAVE_CURL_HTTP_VERSION_2
@@ -1192,7 +1192,7 @@ static CURL *get_curl_handle(void)
11921192
curl_low_speed_time);
11931193
}
11941194

1195-
curl_easy_setopt(result, CURLOPT_MAXREDIRS, 20);
1195+
curl_easy_setopt(result, CURLOPT_MAXREDIRS, 20L);
11961196
curl_easy_setopt(result, CURLOPT_POSTREDIR, CURL_REDIR_POST_ALL);
11971197

11981198
#ifdef GIT_CURL_HAVE_CURLOPT_PROTOCOLS_STR
@@ -1226,7 +1226,7 @@ static CURL *get_curl_handle(void)
12261226
user_agent ? user_agent : git_user_agent());
12271227

12281228
if (curl_ftp_no_epsv)
1229-
curl_easy_setopt(result, CURLOPT_FTP_USE_EPSV, 0);
1229+
curl_easy_setopt(result, CURLOPT_FTP_USE_EPSV, 0L);
12301230

12311231
if (curl_ssl_try)
12321232
curl_easy_setopt(result, CURLOPT_USE_SSL, CURLUSESSL_TRY);

remote-curl.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -876,12 +876,12 @@ static int probe_rpc(struct rpc_state *rpc, struct slot_results *results)
876876
headers = curl_slist_append(headers, rpc->hdr_content_type);
877877
headers = curl_slist_append(headers, rpc->hdr_accept);
878878

879-
curl_easy_setopt(slot->curl, CURLOPT_NOBODY, 0);
880-
curl_easy_setopt(slot->curl, CURLOPT_POST, 1);
879+
curl_easy_setopt(slot->curl, CURLOPT_NOBODY, 0L);
880+
curl_easy_setopt(slot->curl, CURLOPT_POST, 1L);
881881
curl_easy_setopt(slot->curl, CURLOPT_URL, rpc->service_url);
882882
curl_easy_setopt(slot->curl, CURLOPT_ENCODING, NULL);
883883
curl_easy_setopt(slot->curl, CURLOPT_POSTFIELDS, "0000");
884-
curl_easy_setopt(slot->curl, CURLOPT_POSTFIELDSIZE, 4);
884+
curl_easy_setopt(slot->curl, CURLOPT_POSTFIELDSIZE, 4L);
885885
curl_easy_setopt(slot->curl, CURLOPT_HTTPHEADER, headers);
886886
curl_easy_setopt(slot->curl, CURLOPT_WRITEFUNCTION, fwrite_buffer);
887887
curl_easy_setopt(slot->curl, CURLOPT_WRITEDATA, &buf);

0 commit comments

Comments
 (0)