| 1 |
#include <resolv.h> |
| 2 |
|
| 3 |
int __dn_expand(const unsigned char *base, const unsigned char *end, const unsigned char *src, char *dest, int space) |
| 4 |
{ |
| 5 |
const unsigned char *p = src; |
| 6 |
char *dend, *dbegin = dest; |
| 7 |
int len = -1, i, j; |
| 8 |
if (p==end || space <= 0) return -1; |
| 9 |
dend = dest + (space > 254 ? 254 : space); |
| 10 |
/* detect reference loop using an iteration counter */ |
| 11 |
for (i=0; i < end-base; i+=2) { |
| 12 |
/* loop invariants: p<end, dest<dend */ |
| 13 |
if (*p & 0xc0) { |
| 14 |
if (p+1==end) return -1; |
| 15 |
j = ((p[0] & 0x3f) << 8) | p[1]; |
| 16 |
if (len < 0) len = p+2-src; |
| 17 |
if (j >= end-base) return -1; |
| 18 |
p = base+j; |
| 19 |
} else if (*p) { |
| 20 |
if (dest != dbegin) *dest++ = '.'; |
| 21 |
j = *p++; |
| 22 |
if (j >= end-p || j >= dend-dest) return -1; |
| 23 |
while (j--) *dest++ = *p++; |
| 24 |
} else { |
| 25 |
*dest = 0; |
| 26 |
if (len < 0) len = p+1-src; |
| 27 |
return len; |
| 28 |
} |
| 29 |
} |
| 30 |
return -1; |
| 31 |
} |
| 32 |
|
| 33 |
weak_alias(__dn_expand, dn_expand); |