public inbox for cygwin-patches@cygwin.com
 help / color / mirror / Atom feed
* Cygwin: resolver: more fixes
@ 2022-01-18 22:39 Anton Lavrentiev
  2022-01-18 22:39 ` [PATCH 1/2] Cygwin: resolver: Fix to match response ID with request ID Anton Lavrentiev
  2022-01-18 22:39 ` [PATCH 2/2] Cygwin: resolver: Targets in SRV DNS responses may not be compressed Anton Lavrentiev
  0 siblings, 2 replies; 3+ messages in thread
From: Anton Lavrentiev @ 2022-01-18 22:39 UTC (permalink / raw)
  To: cygwin-patches

Proposed are two fixes for more little bugs in the resolver.  The first
one fixes the ID field returned in the response to match the ID of the
request (even in the case when the OS-supplied native resolver is used).
The second one is about the standard compliance (when the response is
relayed from the native OS resolver):  the targets in SRV records
should never be compressed.



^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH 1/2] Cygwin: resolver: Fix to match response ID with request ID
  2022-01-18 22:39 Cygwin: resolver: more fixes Anton Lavrentiev
@ 2022-01-18 22:39 ` Anton Lavrentiev
  2022-01-18 22:39 ` [PATCH 2/2] Cygwin: resolver: Targets in SRV DNS responses may not be compressed Anton Lavrentiev
  1 sibling, 0 replies; 3+ messages in thread
From: Anton Lavrentiev @ 2022-01-18 22:39 UTC (permalink / raw)
  To: cygwin-patches

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
---
 winsup/cygwin/libc/minires-os-if.c | 6 +++++-
 winsup/cygwin/libc/minires.c       | 7 ++++++-
 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 c4183db9c..8d3178f70 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 fdc6087f5..b540f6a1b 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)
-- 
2.33.0


^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH 2/2] Cygwin: resolver: Targets in SRV DNS responses may not be compressed
  2022-01-18 22:39 Cygwin: resolver: more fixes Anton Lavrentiev
  2022-01-18 22:39 ` [PATCH 1/2] Cygwin: resolver: Fix to match response ID with request ID Anton Lavrentiev
@ 2022-01-18 22:39 ` Anton Lavrentiev
  1 sibling, 0 replies; 3+ messages in thread
From: Anton Lavrentiev @ 2022-01-18 22:39 UTC (permalink / raw)
  To: cygwin-patches

RFC2782 clearly says so yet it's a common misconception to perform the
compression in the violation of the standard.  This patch fixes that
---
 winsup/cygwin/libc/minires-os-if.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/winsup/cygwin/libc/minires-os-if.c b/winsup/cygwin/libc/minires-os-if.c
index 8d3178f70..5da1c0c55 100644
--- a/winsup/cygwin/libc/minires-os-if.c
+++ b/winsup/cygwin/libc/minires-os-if.c
@@ -159,6 +159,7 @@ static unsigned char * write_record(unsigned char * ptr, PDNS_RECORD rr,
       PUTSHORT(rr->Data.SRV.wWeight, ptr);
       PUTSHORT(rr->Data.SRV.wPort, ptr);
     }
+    dnptrs = 0;  /* compression not allowed */
     PUTDOMAIN(rr->Data.SRV.pNameTarget, ptr);
     break;
   default:
-- 
2.33.0


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2022-01-18 22:41 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-01-18 22:39 Cygwin: resolver: more fixes Anton Lavrentiev
2022-01-18 22:39 ` [PATCH 1/2] Cygwin: resolver: Fix to match response ID with request ID Anton Lavrentiev
2022-01-18 22:39 ` [PATCH 2/2] Cygwin: resolver: Targets in SRV DNS responses may not be compressed Anton Lavrentiev

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).