Skip to content

Commit a070d78

Browse files
committed
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)
1 parent 432c425 commit a070d78

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

src/lib/ares_process.c

+4-6
Original file line numberDiff line numberDiff line change
@@ -1065,6 +1065,7 @@ static ares_status_t open_socket(ares_channel channel,
10651065
unsigned short port;
10661066
struct server_connection *conn;
10671067
ares__llist_node_t *node;
1068+
int type = is_tcp?SOCK_STREAM:SOCK_DGRAM;
10681069

10691070
if (is_tcp) {
10701071
port = aresx_sitous(server->addr.tcp_port?
@@ -1098,8 +1099,7 @@ static ares_status_t open_socket(ares_channel channel,
10981099
}
10991100

11001101
/* Acquire a socket. */
1101-
s = ares__open_socket(channel, server->addr.family,
1102-
is_tcp?SOCK_STREAM:SOCK_DGRAM, 0);
1102+
s = ares__open_socket(channel, server->addr.family, type, 0);
11031103
if (s == ARES_SOCKET_BAD)
11041104
return ARES_ECONNREFUSED;
11051105

@@ -1129,8 +1129,7 @@ static ares_status_t open_socket(ares_channel channel,
11291129
#endif
11301130

11311131
if (channel->sock_config_cb) {
1132-
int err = channel->sock_config_cb(s, SOCK_STREAM,
1133-
channel->sock_config_cb_data);
1132+
int err = channel->sock_config_cb(s, type, channel->sock_config_cb_data);
11341133
if (err < 0) {
11351134
ares__close_socket(channel, s);
11361135
return ARES_ECONNREFUSED;
@@ -1148,8 +1147,7 @@ static ares_status_t open_socket(ares_channel channel,
11481147
}
11491148

11501149
if (channel->sock_create_cb) {
1151-
int err = channel->sock_create_cb(s, SOCK_STREAM,
1152-
channel->sock_create_cb_data);
1150+
int err = channel->sock_create_cb(s, type, channel->sock_create_cb_data);
11531151
if (err < 0) {
11541152
ares__close_socket(channel, s);
11551153
return ARES_ECONNREFUSED;

0 commit comments

Comments
 (0)