Commit b17557f9 authored by Tobias Stoeckmann's avatar Tobias Stoeckmann Committed by Ulrich Sibiller

The validation of server responses avoids out of boundary accesses.

v2: FontNames.c return a NULL list whenever a single length field from the server is incohent. Signed-off-by: 's avatarTobias Stoeckmann <tobias@stoeckmann.org> Reviewed-by: 's avatarMatthieu Herrb <matthieu@herrb.eu> Backported-to-NX-by: 's avatarUlrich Sibiller <uli42@gmx.de>
parent 68e3ee67
...@@ -66,7 +66,7 @@ int *actualCount) /* RETURN */ ...@@ -66,7 +66,7 @@ int *actualCount) /* RETURN */
if (rep.nFonts) { if (rep.nFonts) {
flist = Xmalloc (rep.nFonts * sizeof(char *)); flist = Xmalloc (rep.nFonts * sizeof(char *));
if (rep.length < (INT_MAX >> 2)) { if (rep.length > 0 && rep.length < (INT_MAX >> 2)) {
rlen = rep.length << 2; rlen = rep.length << 2;
ch = Xmalloc(rlen + 1); ch = Xmalloc(rlen + 1);
/* +1 to leave room for last null-terminator */ /* +1 to leave room for last null-terminator */
...@@ -93,11 +93,22 @@ int *actualCount) /* RETURN */ ...@@ -93,11 +93,22 @@ int *actualCount) /* RETURN */
if (ch + length < chend) { if (ch + length < chend) {
flist[i] = ch + 1; /* skip over length */ flist[i] = ch + 1; /* skip over length */
ch += length + 1; /* find next length ... */ ch += length + 1; /* find next length ... */
length = *(unsigned char *)ch; if (ch <= chend) {
*ch = '\0'; /* and replace with null-termination */ length = *(unsigned char *)ch;
count++; *ch = '\0'; /* and replace with null-termination */
} else count++;
flist[i] = NULL; } else {
Xfree(flist);
flist = NULL;
count = 0;
break;
}
} else {
Xfree(flist);
flist = NULL;
count = 0;
break;
}
} }
} }
*actualCount = count; *actualCount = count;
......
...@@ -55,7 +55,7 @@ char **XListExtensions( ...@@ -55,7 +55,7 @@ char **XListExtensions(
if (rep.nExtensions) { if (rep.nExtensions) {
list = Xmalloc (rep.nExtensions * sizeof (char *)); list = Xmalloc (rep.nExtensions * sizeof (char *));
if (rep.length < (INT_MAX >> 2)) { if (rep.length > 0 && rep.length < (INT_MAX >> 2)) {
rlen = rep.length << 2; rlen = rep.length << 2;
ch = Xmalloc (rlen + 1); ch = Xmalloc (rlen + 1);
/* +1 to leave room for last null-terminator */ /* +1 to leave room for last null-terminator */
...@@ -80,9 +80,13 @@ char **XListExtensions( ...@@ -80,9 +80,13 @@ char **XListExtensions(
if (ch + length < chend) { if (ch + length < chend) {
list[i] = ch+1; /* skip over length */ list[i] = ch+1; /* skip over length */
ch += length + 1; /* find next length ... */ ch += length + 1; /* find next length ... */
length = *ch; if (ch <= chend) {
*ch = '\0'; /* and replace with null-termination */ length = *ch;
count++; *ch = '\0'; /* and replace with null-termination */
count++;
} else {
list[i] = NULL;
}
} else } else
list[i] = NULL; list[i] = NULL;
} }
......
...@@ -42,7 +42,8 @@ XGetModifierMapping(register Display *dpy) ...@@ -42,7 +42,8 @@ XGetModifierMapping(register Display *dpy)
GetEmptyReq(GetModifierMapping, req); GetEmptyReq(GetModifierMapping, req);
(void) _XReply (dpy, (xReply *)&rep, 0, xFalse); (void) _XReply (dpy, (xReply *)&rep, 0, xFalse);
if (rep.length < (INT_MAX >> 2)) { if (rep.length < (INT_MAX >> 2) &&
(rep.length >> 1) == rep.numKeyPerModifier) {
nbytes = (unsigned long)rep.length << 2; nbytes = (unsigned long)rep.length << 2;
res = Xmalloc(sizeof (XModifierKeymap)); res = Xmalloc(sizeof (XModifierKeymap));
if (res) if (res)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment