Commit 36f1dae7 authored by Mike DePaulo's avatar Mike DePaulo Committed by Mike Gabriel

CVE-2014-0209: integer overflow of realloc() size in lexAlias() from…

CVE-2014-0209: integer overflow of realloc() size in lexAlias() from xorg/lib/libXfont commit 05c8020a49416dd8b7510cbba45ce4f3fc81a7dc lexAlias() reads from a file in a loop. It does this by starting with a 64 byte buffer. If that size limit is hit, it does a realloc of the buffer size << 1, basically doubling the needed length every time the length limit is hit. Eventually, this will shift out to 0 (for a length of ~4gig), and that length will be passed on to realloc(). A length of 0 (with a valid pointer) causes realloc to free the buffer on most POSIX platforms, but the caller will still have a pointer to it, leading to use after free issues.
parent f53f2474
...@@ -45,6 +45,7 @@ in this Software without prior written authorization from The Open Group. ...@@ -45,6 +45,7 @@ in this Software without prior written authorization from The Open Group.
#include <sys/types.h> #include <sys/types.h>
#include <sys/stat.h> #include <sys/stat.h>
#include <errno.h> #include <errno.h>
#include <limits.h>
static Bool AddFileNameAliases ( FontDirectoryPtr dir ); static Bool AddFileNameAliases ( FontDirectoryPtr dir );
static int ReadFontAlias ( char *directory, Bool isFile, static int ReadFontAlias ( char *directory, Bool isFile,
...@@ -373,6 +374,9 @@ lexAlias(FILE *file, char **lexToken) ...@@ -373,6 +374,9 @@ lexAlias(FILE *file, char **lexToken)
int nsize; int nsize;
char *nbuf; char *nbuf;
if (tokenSize >= (INT_MAX >> 2))
/* Stop before we overflow */
return EALLOC;
nsize = tokenSize ? (tokenSize << 1) : 64; nsize = tokenSize ? (tokenSize << 1) : 64;
nbuf = (char *) xrealloc(tokenBuf, nsize); nbuf = (char *) xrealloc(tokenBuf, nsize);
if (!nbuf) if (!nbuf)
......
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