From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2155) id C01033857815; Wed, 19 Jan 2022 07:55:07 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C01033857815 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Corinna Vinschen To: cygwin-cvs@sourceware.org Subject: [newlib-cygwin/cygwin-3_3-branch] Cygwin: resolver: A few fixes for cygwin_query() X-Act-Checkin: newlib-cygwin X-Git-Author: Anton Lavrentiev via Cygwin-patches X-Git-Refname: refs/heads/cygwin-3_3-branch X-Git-Oldrev: 3eba4cb6762a6bbe71c5324437f39f7d6a9e4cf8 X-Git-Newrev: b4ed35e2d75f9b4c0a77e26346e8647eaa739c6c Message-Id: <20220119075507.C01033857815@sourceware.org> Date: Wed, 19 Jan 2022 07:55:07 +0000 (GMT) X-BeenThere: cygwin-cvs@cygwin.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Cygwin core component git logs List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 19 Jan 2022 07:55:07 -0000 https://sourceware.org/git/gitweb.cgi?p=3Dnewlib-cygwin.git;h=3Db4ed35e2d75= f9b4c0a77e26346e8647eaa739c6c commit b4ed35e2d75f9b4c0a77e26346e8647eaa739c6c Author: Anton Lavrentiev via Cygwin-patches Date: Tue Jan 18 16:34:34 2022 -0500 Cygwin: resolver: A few fixes for cygwin_query() =20 - Make sure the answer buffer is properly cleared so there is no traili= ng garbage when the response does not fit entirely in; - Make sure an internal decomp failure gets reported correctly (w/retur= n code -1); - Make sure that the buffer is not overrun when filling out the header. Diff: --- winsup/cygwin/libc/minires-os-if.c | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/winsup/cygwin/libc/minires-os-if.c b/winsup/cygwin/libc/minire= s-os-if.c index 55adff22e..a71c37414 100644 --- a/winsup/cygwin/libc/minires-os-if.c +++ b/winsup/cygwin/libc/minires-os-if.c @@ -193,6 +193,8 @@ static int cygwin_query(res_state statp, const char * D= omName, int Class, int Ty dnptrs[0] =3D AnsPtr; dnptrs[1] =3D NULL; =20 + memset(AnsPtr, 0, AnsLength); + if (Class !=3D ns_c_in) { errno =3D ENOSYS; statp->res_h_errno =3D NETDB_INTERNAL; @@ -214,7 +216,7 @@ static int cygwin_query(res_state statp, const char * D= omName, int Class, int Ty switch (res) { case ERROR_INVALID_NAME: errno =3D EINVAL; - statp->res_h_errno =3D NETDB_INTERNAL;; + statp->res_h_errno =3D NETDB_INTERNAL; break; case ERROR_TIMEOUT: statp->res_h_errno =3D TRY_AGAIN; @@ -259,8 +261,9 @@ static int cygwin_query(res_state statp, const char * D= omName, int Class, int Ty /* No question. Adopt the first name as the name in the question */ if ((len =3D dn_comp(rr->pName, ptr, AnsLength - 4, dnptrs, &dnptrs[DIM(dnptrs) - 1])) < 0) { - ptr =3D NULL; - break; + statp->res_h_errno =3D NETDB_INTERNAL; /* dn_comp sets errno */ + len =3D -1; + goto done; } ptr +=3D len; PUTSHORT(Type, ptr); @@ -289,11 +292,13 @@ static int cygwin_query(res_state statp, const char *= DomName, int Class, int Ty =20 len =3D ptr - AnsPtr; done: - ptr =3D AnsPtr; - PUTSHORT(0, ptr); /* Id */ - PUTSHORT((QR << 8) + RA + RD, ptr); - for (section =3D 0; section < DIM(counts); section++) { - PUTSHORT(counts[section], ptr); + if (HFIXEDSZ <=3D AnsLength) { + ptr =3D AnsPtr; + PUTSHORT(0, ptr); /* Id */ + PUTSHORT((QR << 8) + RA + RD, ptr); + for (section =3D 0; section < DIM(counts); section++) { + PUTSHORT(counts[section], ptr); + } } return len; }