aboutsummaryrefslogtreecommitdiff
path: root/winsup
diff options
context:
space:
mode:
authorAnton Lavrentiev via Cygwin-patches <cygwin-patches@cygwin.com>2022-01-18 17:39:15 -0500
committerCorinna Vinschen <corinna@vinschen.de>2022-01-19 08:05:18 +0100
commit905f51d7978e09b8f21d7442c58751fdf775c637 (patch)
treec3c63440d01bcd8627cf1e1ae3770d2709f9e1df /winsup
parent12bf36f72b7e6019a3adb60d86e65262f43a9311 (diff)
downloadnewlib-905f51d7978e09b8f21d7442c58751fdf775c637.zip
newlib-905f51d7978e09b8f21d7442c58751fdf775c637.tar.gz
newlib-905f51d7978e09b8f21d7442c58751fdf775c637.tar.bz2
Cygwin: resolver: Fix to match response ID with request ID
In case when the native OS resolver is used (via os_query) the returned response ID is always 0. It should actually match the ID passed in to res_send() in the DNS request header. This patch fixes that
Diffstat (limited to 'winsup')
-rw-r--r--winsup/cygwin/libc/minires-os-if.c6
-rw-r--r--winsup/cygwin/libc/minires.c7
2 files changed, 11 insertions, 2 deletions
diff --git a/winsup/cygwin/libc/minires-os-if.c b/winsup/cygwin/libc/minires-os-if.c
index c4183db..8d3178f 100644
--- a/winsup/cygwin/libc/minires-os-if.c
+++ b/winsup/cygwin/libc/minires-os-if.c
@@ -189,10 +189,14 @@ static int cygwin_query(res_state statp, const char * DomName, int Class, int Ty
DWORD section;
int len, counts[4] = {0, 0, 0, 0}, debug = statp->options & RES_DEBUG;
unsigned char * dnptrs[256], * ptr;
+ unsigned short Id = 0;
dnptrs[0] = AnsPtr;
dnptrs[1] = NULL;
+ if (AnsLength >= 2)
+ memcpy(&Id, AnsPtr, 2);
+
memset(AnsPtr, 0, AnsLength);
if (Class != ns_c_in) {
@@ -294,7 +298,7 @@ static int cygwin_query(res_state statp, const char * DomName, int Class, int Ty
done:
if (HFIXEDSZ <= AnsLength) {
ptr = AnsPtr;
- PUTSHORT(0, ptr); /* Id */
+ PUTSHORT(Id, ptr);
PUTSHORT((QR << 8) + RA + RD, ptr);
for (section = 0; section < DIM(counts); section++) {
PUTSHORT(counts[section], ptr);
diff --git a/winsup/cygwin/libc/minires.c b/winsup/cygwin/libc/minires.c
index fdc6087..b540f6a 100644
--- a/winsup/cygwin/libc/minires.c
+++ b/winsup/cygwin/libc/minires.c
@@ -450,6 +450,8 @@ int res_nsend( res_state statp, const unsigned char * MsgPtr,
ptr += len;
GETSHORT(Type, ptr);
GETSHORT(Class, ptr);
+ if (AnsLength >= 2)
+ memcpy(AnsPtr, MsgPtr, 2);
return ((os_query_t *) statp->os_query)(statp, DomName, Class, Type, AnsPtr, AnsLength);
}
else {
@@ -709,8 +711,11 @@ int res_nquery( res_state statp, const char * DomName, int Class, int Type,
statp->res_h_errno = NETDB_SUCCESS;
/* If a hook exists to a native implementation, use it */
- if (statp->os_query)
+ if (statp->os_query) {
+ if (AnsLength >= 2)
+ memset(AnsPtr, 0/*Id*/, 2);
return ((os_query_t *) statp->os_query)(statp, DomName, Class, Type, AnsPtr, AnsLength);
+ }
if ((len = res_nmkquery (statp, QUERY, DomName, Class, Type,
0, 0, 0, packet, PACKETSZ)) < 0)