1
0
mirror of https://sourceware.org/git/glibc.git synced 2025-08-07 06:43:00 +03:00

(getanswer_r): Correctly track usage of user-provided buffer.

This commit is contained in:
Ulrich Drepper
1999-06-11 19:46:54 +00:00
parent c52bbc7e7f
commit 560d3b76d8

View File

@@ -319,6 +319,15 @@ getanswer_r (const querybuf *answer, int anslen, const char *qname, int qtype,
int (*name_ok) __P ((const char *)); int (*name_ok) __P ((const char *));
u_char packtmp[NS_MAXCDNAME]; u_char packtmp[NS_MAXCDNAME];
if (linebuflen < 0)
{
/* The buffer is too small. */
too_small:
*errnop = ERANGE;
*h_errnop = NETDB_INTERNAL;
return NSS_STATUS_TRYAGAIN;
}
tname = qname; tname = qname;
result->h_name = NULL; result->h_name = NULL;
end_of_message = answer->buf + anslen; end_of_message = answer->buf + anslen;
@@ -354,11 +363,7 @@ getanswer_r (const querybuf *answer, int anslen, const char *qname, int qtype,
if (n != -1 && __ns_name_ntop (packtmp, bp, linebuflen) == -1) if (n != -1 && __ns_name_ntop (packtmp, bp, linebuflen) == -1)
{ {
if (errno == EMSGSIZE) if (errno == EMSGSIZE)
{ goto too_small;
*errnop = ERANGE;
*h_errnop = NETDB_INTERNAL;
return NSS_STATUS_TRYAGAIN;
}
n = -1; n = -1;
} }
@@ -389,6 +394,8 @@ getanswer_r (const querybuf *answer, int anslen, const char *qname, int qtype,
result->h_name = bp; result->h_name = bp;
bp += n; bp += n;
linebuflen -= n; linebuflen -= n;
if (linebuflen < 0)
goto too_small;
/* The qname can be abbreviated, but h_name is now absolute. */ /* The qname can be abbreviated, but h_name is now absolute. */
qname = result->h_name; qname = result->h_name;
} }
@@ -602,6 +609,7 @@ getanswer_r (const querybuf *answer, int anslen, const char *qname, int qtype,
linebuflen -= nn; linebuflen -= nn;
} }
linebuflen -= sizeof (align) - ((u_long) bp % sizeof (align));
bp += sizeof (align) - ((u_long) bp % sizeof (align)); bp += sizeof (align) - ((u_long) bp % sizeof (align));
if (n >= linebuflen) if (n >= linebuflen)