Cygwin: resolver: A few fixes for cygwin_query()
- Make sure the answer buffer is properly cleared so there is no trailing garbage when the response does not fit entirely in; - Make sure an internal decomp failure gets reported correctly (w/return code -1); - Make sure that the buffer is not overrun when filling out the header.
This commit is contained in:
parent
fa279a583d
commit
12bf36f72b
|
@ -193,6 +193,8 @@ static int cygwin_query(res_state statp, const char * DomName, int Class, int Ty
|
||||||
dnptrs[0] = AnsPtr;
|
dnptrs[0] = AnsPtr;
|
||||||
dnptrs[1] = NULL;
|
dnptrs[1] = NULL;
|
||||||
|
|
||||||
|
memset(AnsPtr, 0, AnsLength);
|
||||||
|
|
||||||
if (Class != ns_c_in) {
|
if (Class != ns_c_in) {
|
||||||
errno = ENOSYS;
|
errno = ENOSYS;
|
||||||
statp->res_h_errno = NETDB_INTERNAL;
|
statp->res_h_errno = NETDB_INTERNAL;
|
||||||
|
@ -214,7 +216,7 @@ static int cygwin_query(res_state statp, const char * DomName, int Class, int Ty
|
||||||
switch (res) {
|
switch (res) {
|
||||||
case ERROR_INVALID_NAME:
|
case ERROR_INVALID_NAME:
|
||||||
errno = EINVAL;
|
errno = EINVAL;
|
||||||
statp->res_h_errno = NETDB_INTERNAL;;
|
statp->res_h_errno = NETDB_INTERNAL;
|
||||||
break;
|
break;
|
||||||
case ERROR_TIMEOUT:
|
case ERROR_TIMEOUT:
|
||||||
statp->res_h_errno = TRY_AGAIN;
|
statp->res_h_errno = TRY_AGAIN;
|
||||||
|
@ -259,8 +261,9 @@ static int cygwin_query(res_state statp, const char * DomName, int Class, int Ty
|
||||||
/* No question. Adopt the first name as the name in the question */
|
/* No question. Adopt the first name as the name in the question */
|
||||||
if ((len = dn_comp(rr->pName, ptr, AnsLength - 4,
|
if ((len = dn_comp(rr->pName, ptr, AnsLength - 4,
|
||||||
dnptrs, &dnptrs[DIM(dnptrs) - 1])) < 0) {
|
dnptrs, &dnptrs[DIM(dnptrs) - 1])) < 0) {
|
||||||
ptr = NULL;
|
statp->res_h_errno = NETDB_INTERNAL; /* dn_comp sets errno */
|
||||||
break;
|
len = -1;
|
||||||
|
goto done;
|
||||||
}
|
}
|
||||||
ptr += len;
|
ptr += len;
|
||||||
PUTSHORT(Type, ptr);
|
PUTSHORT(Type, ptr);
|
||||||
|
@ -289,12 +292,14 @@ static int cygwin_query(res_state statp, const char * DomName, int Class, int Ty
|
||||||
|
|
||||||
len = ptr - AnsPtr;
|
len = ptr - AnsPtr;
|
||||||
done:
|
done:
|
||||||
|
if (HFIXEDSZ <= AnsLength) {
|
||||||
ptr = AnsPtr;
|
ptr = AnsPtr;
|
||||||
PUTSHORT(0, ptr); /* Id */
|
PUTSHORT(0, ptr); /* Id */
|
||||||
PUTSHORT((QR << 8) + RA + RD, ptr);
|
PUTSHORT((QR << 8) + RA + RD, ptr);
|
||||||
for (section = 0; section < DIM(counts); section++) {
|
for (section = 0; section < DIM(counts); section++) {
|
||||||
PUTSHORT(counts[section], ptr);
|
PUTSHORT(counts[section], ptr);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return len;
|
return len;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue