Socket callbacks were passed SOCK_STREAM instead of SOCK_DGRAM on udp

A regression was introduced in 1.20.0 that would pass SOCK_STREAM on udp
connections due to code refactoring.  If a client application validated this
data, it could cause issues as seen in gRPC.

Fixes Issue: #571
Fix By: Brad House (@bradh352)
pull/575/head
Brad House 1 year ago
parent 432c42572d
commit a070d7835d
  1. 10
      src/lib/ares_process.c

@ -1065,6 +1065,7 @@ static ares_status_t open_socket(ares_channel channel,
unsigned short port; unsigned short port;
struct server_connection *conn; struct server_connection *conn;
ares__llist_node_t *node; ares__llist_node_t *node;
int type = is_tcp?SOCK_STREAM:SOCK_DGRAM;
if (is_tcp) { if (is_tcp) {
port = aresx_sitous(server->addr.tcp_port? port = aresx_sitous(server->addr.tcp_port?
@ -1098,8 +1099,7 @@ static ares_status_t open_socket(ares_channel channel,
} }
/* Acquire a socket. */ /* Acquire a socket. */
s = ares__open_socket(channel, server->addr.family, s = ares__open_socket(channel, server->addr.family, type, 0);
is_tcp?SOCK_STREAM:SOCK_DGRAM, 0);
if (s == ARES_SOCKET_BAD) if (s == ARES_SOCKET_BAD)
return ARES_ECONNREFUSED; return ARES_ECONNREFUSED;
@ -1129,8 +1129,7 @@ static ares_status_t open_socket(ares_channel channel,
#endif #endif
if (channel->sock_config_cb) { if (channel->sock_config_cb) {
int err = channel->sock_config_cb(s, SOCK_STREAM, int err = channel->sock_config_cb(s, type, channel->sock_config_cb_data);
channel->sock_config_cb_data);
if (err < 0) { if (err < 0) {
ares__close_socket(channel, s); ares__close_socket(channel, s);
return ARES_ECONNREFUSED; return ARES_ECONNREFUSED;
@ -1148,8 +1147,7 @@ static ares_status_t open_socket(ares_channel channel,
} }
if (channel->sock_create_cb) { if (channel->sock_create_cb) {
int err = channel->sock_create_cb(s, SOCK_STREAM, int err = channel->sock_create_cb(s, type, channel->sock_create_cb_data);
channel->sock_create_cb_data);
if (err < 0) { if (err < 0) {
ares__close_socket(channel, s); ares__close_socket(channel, s);
return ARES_ECONNREFUSED; return ARES_ECONNREFUSED;

Loading…
Cancel
Save