Skip to content

Commit 820d81c

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 cca1f38 commit 820d81c

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
@@ -731,7 +731,7 @@ static int has_proxy_cert_password(void)
731731

732732
static void set_curl_keepalive(CURL *c)
733733
{
734-
curl_easy_setopt(c, CURLOPT_TCP_KEEPALIVE, 1);
734+
curl_easy_setopt(c, CURLOPT_TCP_KEEPALIVE, 1L);
735735
}
736736

737737
/* Return 1 if redactions have been made, 0 otherwise. */
@@ -1032,13 +1032,13 @@ static CURL *get_curl_handle(void)
10321032
die("curl_easy_init failed");
10331033

10341034
if (!curl_ssl_verify) {
1035-
curl_easy_setopt(result, CURLOPT_SSL_VERIFYPEER, 0);
1036-
curl_easy_setopt(result, CURLOPT_SSL_VERIFYHOST, 0);
1035+
curl_easy_setopt(result, CURLOPT_SSL_VERIFYPEER, 0L);
1036+
curl_easy_setopt(result, CURLOPT_SSL_VERIFYHOST, 0L);
10371037
} else {
10381038
/* Verify authenticity of the peer's certificate */
1039-
curl_easy_setopt(result, CURLOPT_SSL_VERIFYPEER, 1);
1039+
curl_easy_setopt(result, CURLOPT_SSL_VERIFYPEER, 1L);
10401040
/* The name in the cert must match whom we tried to connect */
1041-
curl_easy_setopt(result, CURLOPT_SSL_VERIFYHOST, 2);
1041+
curl_easy_setopt(result, CURLOPT_SSL_VERIFYHOST, 2L);
10421042
}
10431043

10441044
if (curl_http_version) {
@@ -1141,7 +1141,7 @@ static CURL *get_curl_handle(void)
11411141
curl_low_speed_time);
11421142
}
11431143

1144-
curl_easy_setopt(result, CURLOPT_MAXREDIRS, 20);
1144+
curl_easy_setopt(result, CURLOPT_MAXREDIRS, 20L);
11451145
curl_easy_setopt(result, CURLOPT_POSTREDIR, CURL_REDIR_POST_ALL);
11461146

11471147
#ifdef GIT_CURL_HAVE_CURLOPT_PROTOCOLS_STR
@@ -1175,7 +1175,7 @@ static CURL *get_curl_handle(void)
11751175
user_agent ? user_agent : git_user_agent());
11761176

11771177
if (curl_ftp_no_epsv)
1178-
curl_easy_setopt(result, CURLOPT_FTP_USE_EPSV, 0);
1178+
curl_easy_setopt(result, CURLOPT_FTP_USE_EPSV, 0L);
11791179

11801180
if (curl_ssl_try)
11811181
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
@@ -877,12 +877,12 @@ static int probe_rpc(struct rpc_state *rpc, struct slot_results *results)
877877
headers = curl_slist_append(headers, rpc->hdr_content_type);
878878
headers = curl_slist_append(headers, rpc->hdr_accept);
879879

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

0 commit comments

Comments
 (0)