~ubuntu-branches/ubuntu/vivid/musl/vivid

« back to all changes in this revision

Viewing changes to src/network/dn_expand.c

  • Committer: Package Import Robot
  • Author(s): Kevin Bortis
  • Date: 2014-05-26 22:45:52 UTC
  • mfrom: (4.1.4 sid)
  • Revision ID: package-import@ubuntu.com-20140526224552-qrtsct934q29xo0x
Tags: 1.1.4-1
* Import upstream version 1.1.4. (Closes: #754758)
* Fixes possible stack-based buffer overflow CVE-2014-3484 (Closes: #750815) 
* Includes fix for build regression on armhf and armel

Show diffs side-by-side

added added

removed removed

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