|
|
cf1e18 |
From 05c8020a49416dd8b7510cbba45ce4f3fc81a7dc Mon Sep 17 00:00:00 2001
|
|
|
cf1e18 |
From: Alan Coopersmith <alan.coopersmith@oracle.com>
|
|
|
cf1e18 |
Date: Fri, 25 Apr 2014 23:01:48 -0700
|
|
|
cf1e18 |
Subject: [PATCH 02/12] CVE-2014-0209: integer overflow of realloc() size in lexAlias()
|
|
|
cf1e18 |
|
|
|
cf1e18 |
lexAlias() reads from a file in a loop. It does this by starting with a
|
|
|
cf1e18 |
64 byte buffer. If that size limit is hit, it does a realloc of the
|
|
|
cf1e18 |
buffer size << 1, basically doubling the needed length every time the
|
|
|
cf1e18 |
length limit is hit.
|
|
|
cf1e18 |
|
|
|
cf1e18 |
Eventually, this will shift out to 0 (for a length of ~4gig), and that
|
|
|
cf1e18 |
length will be passed on to realloc(). A length of 0 (with a valid
|
|
|
cf1e18 |
pointer) causes realloc to free the buffer on most POSIX platforms,
|
|
|
cf1e18 |
but the caller will still have a pointer to it, leading to use after
|
|
|
cf1e18 |
free issues.
|
|
|
cf1e18 |
|
|
|
cf1e18 |
Reported-by: Ilja Van Sprundel <ivansprundel@ioactive.com>
|
|
|
cf1e18 |
Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
|
|
|
cf1e18 |
Reviewed-by: Adam Jackson <ajax@redhat.com>
|
|
|
cf1e18 |
Reviewed-by: Matthieu Herrb <matthieu@herrb.eu>
|
|
|
cf1e18 |
---
|
|
|
cf1e18 |
src/fontfile/dirfile.c | 4 ++++
|
|
|
cf1e18 |
1 files changed, 4 insertions(+), 0 deletions(-)
|
|
|
cf1e18 |
|
|
|
cf1e18 |
diff --git a/src/fontfile/dirfile.c b/src/fontfile/dirfile.c
|
|
|
cf1e18 |
index cb28333..38ced75 100644
|
|
|
cf1e18 |
--- a/src/fontfile/dirfile.c
|
|
|
cf1e18 |
+++ b/src/fontfile/dirfile.c
|
|
|
cf1e18 |
@@ -42,6 +42,7 @@ in this Software without prior written authorization from The Open Group.
|
|
|
cf1e18 |
#include <sys/types.h>
|
|
|
cf1e18 |
#include <sys/stat.h>
|
|
|
cf1e18 |
#include <errno.h>
|
|
|
cf1e18 |
+#include <limits.h>
|
|
|
cf1e18 |
|
|
|
cf1e18 |
static Bool AddFileNameAliases ( FontDirectoryPtr dir );
|
|
|
cf1e18 |
static int ReadFontAlias ( char *directory, Bool isFile,
|
|
|
cf1e18 |
@@ -376,6 +377,9 @@ lexAlias(FILE *file, char **lexToken)
|
|
|
cf1e18 |
int nsize;
|
|
|
cf1e18 |
char *nbuf;
|
|
|
cf1e18 |
|
|
|
cf1e18 |
+ if (tokenSize >= (INT_MAX >> 2))
|
|
|
cf1e18 |
+ /* Stop before we overflow */
|
|
|
cf1e18 |
+ return EALLOC;
|
|
|
cf1e18 |
nsize = tokenSize ? (tokenSize << 1) : 64;
|
|
|
cf1e18 |
nbuf = realloc(tokenBuf, nsize);
|
|
|
cf1e18 |
if (!nbuf)
|
|
|
cf1e18 |
--
|
|
|
cf1e18 |
1.7.1
|
|
|
cf1e18 |
|