mirror of
https://sourceware.org/git/glibc.git
synced 2025-07-30 22:43:12 +03:00
* include/arpa/nameser.h: Also optimize NS_PUT16 and NS_PUT32.
* resolv/res_mkquery.c: Use NS_PUT16 and NS_PUT32 instead of __putshort and __putlong respectively. Correct buffer overflow check for NS_NOTIFY_OP. * resolv/res_send.c (send_vc): Use ns_put16 instead of putshort.
This commit is contained in:
@ -1,5 +1,12 @@
|
|||||||
2006-05-06 Ulrich Drepper <drepper@redhat.com>
|
2006-05-06 Ulrich Drepper <drepper@redhat.com>
|
||||||
|
|
||||||
|
* include/arpa/nameser.h: Also optimize NS_PUT16 and NS_PUT32.
|
||||||
|
* resolv/res_mkquery.c: Use NS_PUT16 and NS_PUT32 instead of __putshort
|
||||||
|
and __putlong respectively. Correct buffer overflow check for
|
||||||
|
NS_NOTIFY_OP.
|
||||||
|
|
||||||
|
* resolv/res_send.c (send_vc): Use ns_put16 instead of putshort.
|
||||||
|
|
||||||
* resolv/res_send.c (res_queriesmatch): Fix typo in comment.
|
* resolv/res_send.c (res_queriesmatch): Fix typo in comment.
|
||||||
(send_dg): Rewrite error handling to be more compact and avoid
|
(send_dg): Rewrite error handling to be more compact and avoid
|
||||||
double recomputation of timeouts. Pass MSG_NOSIGNAL to send.
|
double recomputation of timeouts. Pass MSG_NOSIGNAL to send.
|
||||||
|
@ -18,10 +18,26 @@
|
|||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
# undef NS_GET32
|
# undef NS_GET32
|
||||||
# define NS_GET32(s, cp) \
|
# define NS_GET32(l, cp) \
|
||||||
do { \
|
do { \
|
||||||
uint32_t *t_cp = (uint32_t *) (cp); \
|
uint32_t *t_cp = (uint32_t *) (cp); \
|
||||||
(s) = ntohl (*t_cp); \
|
(l) = ntohl (*t_cp); \
|
||||||
|
(cp) += NS_INT32SZ; \
|
||||||
|
} while (0)
|
||||||
|
|
||||||
|
# undef NS_PUT16
|
||||||
|
# define NS_PUT16(s, cp) \
|
||||||
|
do { \
|
||||||
|
uint16_t *t_cp = (uint16_t *) (cp); \
|
||||||
|
*t_cp = htons (s); \
|
||||||
|
(cp) += NS_INT16SZ; \
|
||||||
|
} while (0)
|
||||||
|
|
||||||
|
# undef NS_PUT32
|
||||||
|
# define NS_PUT32(l, cp) \
|
||||||
|
do { \
|
||||||
|
uint32_t *t_cp = (uint32_t *) (cp); \
|
||||||
|
*t_cp = htonl (l); \
|
||||||
(cp) += NS_INT32SZ; \
|
(cp) += NS_INT32SZ; \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
|
@ -131,13 +131,13 @@ res_nmkquery(res_state statp,
|
|||||||
int randombits;
|
int randombits;
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
#ifdef RANDOM_BITS
|
# ifdef RANDOM_BITS
|
||||||
RANDOM_BITS (randombits);
|
RANDOM_BITS (randombits);
|
||||||
#else
|
# else
|
||||||
struct timeval tv;
|
struct timeval tv;
|
||||||
__gettimeofday (&tv, NULL);
|
__gettimeofday (&tv, NULL);
|
||||||
randombits = (tv.tv_sec << 8) ^ tv.tv_usec;
|
randombits = (tv.tv_sec << 8) ^ tv.tv_usec;
|
||||||
#endif
|
# endif
|
||||||
}
|
}
|
||||||
while ((randombits & 0xffff) == 0);
|
while ((randombits & 0xffff) == 0);
|
||||||
statp->id = (statp->id + randombits) & 0xffff;
|
statp->id = (statp->id + randombits) & 0xffff;
|
||||||
@ -155,38 +155,36 @@ res_nmkquery(res_state statp,
|
|||||||
* perform opcode specific processing
|
* perform opcode specific processing
|
||||||
*/
|
*/
|
||||||
switch (op) {
|
switch (op) {
|
||||||
case QUERY: /*FALLTHROUGH*/
|
|
||||||
case NS_NOTIFY_OP:
|
case NS_NOTIFY_OP:
|
||||||
|
if ((buflen -= QFIXEDSZ + (data == NULL ? 0 : RRFIXEDSZ)) < 0)
|
||||||
|
return (-1);
|
||||||
|
goto compose;
|
||||||
|
|
||||||
|
case QUERY:
|
||||||
if ((buflen -= QFIXEDSZ) < 0)
|
if ((buflen -= QFIXEDSZ) < 0)
|
||||||
return (-1);
|
return (-1);
|
||||||
|
compose:
|
||||||
if ((n = dn_comp(dname, cp, buflen, dnptrs, lastdnptr)) < 0)
|
if ((n = dn_comp(dname, cp, buflen, dnptrs, lastdnptr)) < 0)
|
||||||
return (-1);
|
return (-1);
|
||||||
cp += n;
|
cp += n;
|
||||||
buflen -= n;
|
buflen -= n;
|
||||||
__putshort(type, cp);
|
NS_PUT16 (type, cp);
|
||||||
cp += INT16SZ;
|
NS_PUT16 (class, cp);
|
||||||
__putshort(class, cp);
|
|
||||||
cp += INT16SZ;
|
|
||||||
hp->qdcount = htons(1);
|
hp->qdcount = htons(1);
|
||||||
if (op == QUERY || data == NULL)
|
if (op == QUERY || data == NULL)
|
||||||
break;
|
break;
|
||||||
/*
|
/*
|
||||||
* Make an additional record for completion domain.
|
* Make an additional record for completion domain.
|
||||||
*/
|
*/
|
||||||
buflen -= RRFIXEDSZ;
|
|
||||||
n = dn_comp((char *)data, cp, buflen, dnptrs, lastdnptr);
|
n = dn_comp((char *)data, cp, buflen, dnptrs, lastdnptr);
|
||||||
if (n < 0)
|
if (__builtin_expect (n < 0, 0))
|
||||||
return (-1);
|
return (-1);
|
||||||
cp += n;
|
cp += n;
|
||||||
buflen -= n;
|
buflen -= n;
|
||||||
__putshort(T_NULL, cp);
|
NS_PUT16 (T_NULL, cp);
|
||||||
cp += INT16SZ;
|
NS_PUT16 (class, cp);
|
||||||
__putshort(class, cp);
|
NS_PUT32 (0, cp);
|
||||||
cp += INT16SZ;
|
NS_PUT16 (0, cp);
|
||||||
__putlong(0, cp);
|
|
||||||
cp += INT32SZ;
|
|
||||||
__putshort(0, cp);
|
|
||||||
cp += INT16SZ;
|
|
||||||
hp->arcount = htons(1);
|
hp->arcount = htons(1);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@ -194,17 +192,13 @@ res_nmkquery(res_state statp,
|
|||||||
/*
|
/*
|
||||||
* Initialize answer section
|
* Initialize answer section
|
||||||
*/
|
*/
|
||||||
if (buflen < 1 + RRFIXEDSZ + datalen)
|
if (__builtin_expect (buflen < 1 + RRFIXEDSZ + datalen, 0))
|
||||||
return (-1);
|
return (-1);
|
||||||
*cp++ = '\0'; /* no domain name */
|
*cp++ = '\0'; /* no domain name */
|
||||||
__putshort(type, cp);
|
NS_PUT16 (type, cp);
|
||||||
cp += INT16SZ;
|
NS_PUT16 (class, cp);
|
||||||
__putshort(class, cp);
|
NS_PUT32 (0, cp);
|
||||||
cp += INT16SZ;
|
NS_PUT16 (datalen, cp);
|
||||||
__putlong(0, cp);
|
|
||||||
cp += INT32SZ;
|
|
||||||
__putshort(datalen, cp);
|
|
||||||
cp += INT16SZ;
|
|
||||||
if (datalen) {
|
if (datalen) {
|
||||||
memcpy(cp, data, datalen);
|
memcpy(cp, data, datalen);
|
||||||
cp += datalen;
|
cp += datalen;
|
||||||
|
@ -674,7 +674,7 @@ send_vc(res_state statp,
|
|||||||
/*
|
/*
|
||||||
* Send length & message
|
* Send length & message
|
||||||
*/
|
*/
|
||||||
putshort((u_short)buflen, (u_char*)&len);
|
ns_put16((u_short)buflen, (u_char*)&len);
|
||||||
evConsIovec(&len, INT16SZ, &iov[0]);
|
evConsIovec(&len, INT16SZ, &iov[0]);
|
||||||
evConsIovec((void*)buf, buflen, &iov[1]);
|
evConsIovec((void*)buf, buflen, &iov[1]);
|
||||||
if (TEMP_FAILURE_RETRY (writev(statp->_vcsock, iov, 2))
|
if (TEMP_FAILURE_RETRY (writev(statp->_vcsock, iov, 2))
|
||||||
|
Reference in New Issue
Block a user