cf-socket: always check Curl_cf_socket_peek() return code

Make it trigger a warning if not.

Reported-by: Joshua Rogers
Closes #18862
This commit is contained in:
Daniel Stenberg 2025-10-06 08:22:39 +02:00
parent 51b85bdc6c
commit decd7e157c
No known key found for this signature in database
GPG key ID: 5CC908FDB71E12C2
5 changed files with 26 additions and 25 deletions

View file

@ -158,7 +158,7 @@ CURLcode Curl_cf_socket_peek(struct Curl_cfilter *cf,
struct Curl_easy *data,
curl_socket_t *psock,
const struct Curl_sockaddr_ex **paddr,
struct ip_quadruple *pip);
struct ip_quadruple *pip) WARN_UNUSED_RESULT;
extern struct Curl_cftype Curl_cft_tcp;
extern struct Curl_cftype Curl_cft_udp;

View file

@ -2480,8 +2480,7 @@ static CURLcode cf_connect_start(struct Curl_cfilter *cf,
if(result)
return result;
Curl_cf_socket_peek(cf->next, data, &ctx->q.sockfd, &sockaddr, NULL);
if(!sockaddr)
if(Curl_cf_socket_peek(cf->next, data, &ctx->q.sockfd, &sockaddr, NULL))
return CURLE_QUIC_CONNECT_ERROR;
ctx->q.local_addrlen = sizeof(ctx->q.local_addr);
rv = getsockname(ctx->q.sockfd, (struct sockaddr *)&ctx->q.local_addr,
@ -2633,9 +2632,9 @@ out:
if(result) {
struct ip_quadruple ip;
Curl_cf_socket_peek(cf->next, data, NULL, NULL, &ip);
infof(data, "QUIC connect to %s port %u failed: %s",
ip.remote_ip, ip.remote_port, curl_easy_strerror(result));
if(!Curl_cf_socket_peek(cf->next, data, NULL, NULL, &ip))
infof(data, "QUIC connect to %s port %u failed: %s",
ip.remote_ip, ip.remote_port, curl_easy_strerror(result));
}
#endif
if(!result && ctx->qconn) {

View file

@ -550,12 +550,12 @@ static CURLcode cf_osslq_ssl_err(struct Curl_cfilter *cf,
int sockerr = SOCKERRNO;
struct ip_quadruple ip;
Curl_cf_socket_peek(cf->next, data, NULL, NULL, &ip);
if(sockerr && detail == SSL_ERROR_SYSCALL)
curlx_strerror(sockerr, extramsg, sizeof(extramsg));
failf(data, "QUIC connect: %s in connection to %s:%d (%s)",
extramsg[0] ? extramsg : osslq_SSL_ERROR_to_str(detail),
ctx->peer.dispname, ip.remote_port, ip.remote_ip);
if(!Curl_cf_socket_peek(cf->next, data, NULL, NULL, &ip))
failf(data, "QUIC connect: %s in connection to %s:%d (%s)",
extramsg[0] ? extramsg : osslq_SSL_ERROR_to_str(detail),
ctx->peer.dispname, ip.remote_port, ip.remote_ip);
}
else {
/* Could be a CERT problem */
@ -1177,8 +1177,8 @@ static CURLcode cf_osslq_ctx_start(struct Curl_cfilter *cf,
goto out;
result = CURLE_QUIC_CONNECT_ERROR;
Curl_cf_socket_peek(cf->next, data, &ctx->q.sockfd, &peer_addr, NULL);
if(!peer_addr)
if(Curl_cf_socket_peek(cf->next, data, &ctx->q.sockfd, &peer_addr, NULL) ||
!peer_addr)
goto out;
ctx->q.local_addrlen = sizeof(ctx->q.local_addr);
@ -1857,9 +1857,9 @@ out:
if(result) {
struct ip_quadruple ip;
Curl_cf_socket_peek(cf->next, data, NULL, NULL, &ip);
infof(data, "QUIC connect to %s port %u failed: %s",
ip.remote_ip, ip.remote_port, curl_easy_strerror(result));
if(!Curl_cf_socket_peek(cf->next, data, NULL, NULL, &ip))
infof(data, "QUIC connect to %s port %u failed: %s",
ip.remote_ip, ip.remote_port, curl_easy_strerror(result));
}
#endif
if(!result)

View file

@ -1303,7 +1303,9 @@ static CURLcode cf_quiche_ctx_open(struct Curl_cfilter *cf,
if(result)
return result;
Curl_cf_socket_peek(cf->next, data, &ctx->q.sockfd, &sockaddr, NULL);
if(Curl_cf_socket_peek(cf->next, data, &ctx->q.sockfd, &sockaddr, NULL))
return CURLE_QUIC_CONNECT_ERROR;
ctx->q.local_addrlen = sizeof(ctx->q.local_addr);
rv = getsockname(ctx->q.sockfd, (struct sockaddr *)&ctx->q.local_addr,
&ctx->q.local_addrlen);

View file

@ -428,9 +428,9 @@ static CURLcode recvmmsg_packets(struct Curl_cfilter *cf,
}
if(!cf->connected && SOCKERRNO == SOCKECONNREFUSED) {
struct ip_quadruple ip;
Curl_cf_socket_peek(cf->next, data, NULL, NULL, &ip);
failf(data, "QUIC: connection to %s port %u refused",
ip.remote_ip, ip.remote_port);
if(!Curl_cf_socket_peek(cf->next, data, NULL, NULL, &ip))
failf(data, "QUIC: connection to %s port %u refused",
ip.remote_ip, ip.remote_port);
result = CURLE_COULDNT_CONNECT;
goto out;
}
@ -521,9 +521,9 @@ static CURLcode recvmsg_packets(struct Curl_cfilter *cf,
}
if(!cf->connected && SOCKERRNO == SOCKECONNREFUSED) {
struct ip_quadruple ip;
Curl_cf_socket_peek(cf->next, data, NULL, NULL, &ip);
failf(data, "QUIC: connection to %s port %u refused",
ip.remote_ip, ip.remote_port);
if(!Curl_cf_socket_peek(cf->next, data, NULL, NULL, &ip))
failf(data, "QUIC: connection to %s port %u refused",
ip.remote_ip, ip.remote_port);
result = CURLE_COULDNT_CONNECT;
goto out;
}
@ -596,9 +596,9 @@ static CURLcode recvfrom_packets(struct Curl_cfilter *cf,
}
if(!cf->connected && SOCKERRNO == SOCKECONNREFUSED) {
struct ip_quadruple ip;
Curl_cf_socket_peek(cf->next, data, NULL, NULL, &ip);
failf(data, "QUIC: connection to %s port %u refused",
ip.remote_ip, ip.remote_port);
if(!Curl_cf_socket_peek(cf->next, data, NULL, NULL, &ip))
failf(data, "QUIC: connection to %s port %u refused",
ip.remote_ip, ip.remote_port);
result = CURLE_COULDNT_CONNECT;
goto out;
}