Commit e386187e authored by Alan Coopersmith's avatar Alan Coopersmith Committed by Ulrich Sibiller

Unbounded recursion in _XimParseStringFile() when parsing include files [CVE-2013-2004 2/2]

parseline() can call _XimParseStringFile() which can call parseline() which can call _XimParseStringFile() which can call parseline() .... eventually causing recursive stack overflow and crash. Limit is set to a include depth of 100 files, which should be enough for all known use cases, but could be adjusted later if necessary. Reported-by: 's avatarIlja Van Sprundel <ivansprundel@ioactive.com> Signed-off-by: 's avatarAlan Coopersmith <alan.coopersmith@oracle.com> Reviewed-by: 's avatarMatthieu Herrb <matthieu.herrb@laas.fr> Signed-off-by: 's avatarJulien Cristau <jcristau@debian.org> Backported-to-NX-by: 's avatarUlrich Sibiller <uli42@gmx.de>
parent bddfee4a
...@@ -58,6 +58,8 @@ extern int _Xmbstoutf8( ...@@ -58,6 +58,8 @@ extern int _Xmbstoutf8(
int len int len
); );
static void parsestringfile(FILE *fp, Xim im, int depth);
/* /*
* Parsing File Format: * Parsing File Format:
* *
...@@ -447,7 +449,8 @@ static int ...@@ -447,7 +449,8 @@ static int
parseline( parseline(
FILE *fp, FILE *fp,
Xim im, Xim im,
char* tokenbuf) char* tokenbuf,
int depth)
{ {
int token; int token;
DTModifier modifier_mask; DTModifier modifier_mask;
...@@ -494,11 +497,13 @@ parseline( ...@@ -494,11 +497,13 @@ parseline(
goto error; goto error;
if ((filename = TransFileName(im, tokenbuf)) == NULL) if ((filename = TransFileName(im, tokenbuf)) == NULL)
goto error; goto error;
if (++depth > 100)
goto error;
infp = _XFopenFile(filename, "r"); infp = _XFopenFile(filename, "r");
Xfree(filename); Xfree(filename);
if (infp == NULL) if (infp == NULL)
goto error; goto error;
_XimParseStringFile(infp, im); parsestringfile(infp, im, depth);
fclose(infp); fclose(infp);
return (0); return (0);
} else if ((token == KEY) && (strcmp("None", tokenbuf) == 0)) { } else if ((token == KEY) && (strcmp("None", tokenbuf) == 0)) {
...@@ -692,6 +697,15 @@ _XimParseStringFile( ...@@ -692,6 +697,15 @@ _XimParseStringFile(
FILE *fp, FILE *fp,
Xim im) Xim im)
{ {
parsestringfile(fp, im, 0);
}
static void
parsestringfile(
FILE *fp,
Xim im,
int depth)
{
char tb[8192]; char tb[8192];
char* tbp; char* tbp;
struct stat st; struct stat st;
...@@ -704,7 +718,7 @@ _XimParseStringFile( ...@@ -704,7 +718,7 @@ _XimParseStringFile(
else tbp = malloc (size); else tbp = malloc (size);
if (tbp != NULL) { if (tbp != NULL) {
while (parseline(fp, im, tbp) >= 0) {} while (parseline(fp, im, tbp, depth) >= 0) {}
if (tbp != tb) free (tbp); if (tbp != tb) free (tbp);
} }
} }
......
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