Skip to content

Commit a686971

Browse files
authored
Merge pull request #24 from verdammelt/reject-zero-length-names
Handle overflow problem reported in #23 Fixes #23
2 parents 5af0791 + cfdd80f commit a686971

File tree

2 files changed

+24
-21
lines changed

2 files changed

+24
-21
lines changed

src/mapi_attr.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,8 @@ mapi_attr_read (size_t len, unsigned char *buf)
211211
CHECKINT32(idx, len); a->names[i].len = GETINT32(buf+idx); idx += 4;
212212

213213
/* read the data into a buffer */
214+
/* read the data into a buffer */
215+
assert(a->names[i].len != 0);
214216
assert(idx+a->names[i].len <= len);
215217
a->names[i].data = unicode_to_utf8(a->names[i].len, buf+idx);
216218

src/util.c

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -85,28 +85,29 @@ unicode_to_utf8 (size_t len, unsigned char* buf)
8585
int j = 0;
8686
unsigned char *utf8 = malloc (3 * len/2 + 1); /* won't get any longer than this */
8787

88-
for (i = 0; i < len - 1; i += 2)
89-
{
90-
uint32 c = GETINT16(buf + i);
91-
if (c <= 0x007f)
92-
{
93-
utf8[j++] = 0x00 | ((c & 0x007f) >> 0);
94-
}
95-
else if (c < 0x07ff)
96-
{
97-
utf8[j++] = 0xc0 | ((c & 0x07c0) >> 6);
98-
utf8[j++] = 0x80 | ((c & 0x003f) >> 0);
99-
}
100-
else
101-
{
102-
utf8[j++] = 0xe0 | ((c & 0xf000) >> 12);
103-
utf8[j++] = 0x80 | ((c & 0x0fc0) >> 6);
104-
utf8[j++] = 0x80 | ((c & 0x003f) >> 0);
105-
}
88+
if (len > 0) {
89+
for (i = 0; i < len - 1; i += 2)
90+
{
91+
uint32 c = GETINT16(buf + i);
92+
if (c <= 0x007f)
93+
{
94+
utf8[j++] = 0x00 | ((c & 0x007f) >> 0);
95+
}
96+
else if (c < 0x07ff)
97+
{
98+
utf8[j++] = 0xc0 | ((c & 0x07c0) >> 6);
99+
utf8[j++] = 0x80 | ((c & 0x003f) >> 0);
100+
}
101+
else
102+
{
103+
utf8[j++] = 0xe0 | ((c & 0xf000) >> 12);
104+
utf8[j++] = 0x80 | ((c & 0x0fc0) >> 6);
105+
utf8[j++] = 0x80 | ((c & 0x003f) >> 0);
106+
}
107+
}
106108
}
107-
109+
108110
utf8[j] = '\0';
109-
111+
110112
return utf8;
111113
}
112-

0 commit comments

Comments
 (0)