open-src/lib/libX11/CVE-2013-2004.patch
author Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
Wed, 15 May 2013 13:44:02 -0700
changeset 1345 d5dacbb8de2b
permissions -rw-r--r--
16673783 problem in X11/LIBRARIES 16674478 problem in X11/LIBRARIES
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1345
d5dacbb8de2b 16673783 problem in X11/LIBRARIES
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents:
diff changeset
     1
From 5004f53889bf65aa9e78cea7a01a51948839dce3 Mon Sep 17 00:00:00 2001
d5dacbb8de2b 16673783 problem in X11/LIBRARIES
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents:
diff changeset
     2
From: Alan Coopersmith <[email protected]>
d5dacbb8de2b 16673783 problem in X11/LIBRARIES
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents:
diff changeset
     3
Date: Sat, 2 Mar 2013 12:01:39 -0800
d5dacbb8de2b 16673783 problem in X11/LIBRARIES
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents:
diff changeset
     4
Subject: [PATCH:libX11 22/38] Unbounded recursion in GetDatabase() when
d5dacbb8de2b 16673783 problem in X11/LIBRARIES
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents:
diff changeset
     5
 parsing include files [CVE-2013-2004 1/2]
d5dacbb8de2b 16673783 problem in X11/LIBRARIES
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents:
diff changeset
     6
d5dacbb8de2b 16673783 problem in X11/LIBRARIES
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents:
diff changeset
     7
GetIncludeFile() can call GetDatabase() which can call GetIncludeFile()
d5dacbb8de2b 16673783 problem in X11/LIBRARIES
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents:
diff changeset
     8
which can call GetDatabase() which can call GetIncludeFile() ....
d5dacbb8de2b 16673783 problem in X11/LIBRARIES
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents:
diff changeset
     9
eventually causing recursive stack overflow and crash.
d5dacbb8de2b 16673783 problem in X11/LIBRARIES
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents:
diff changeset
    10
d5dacbb8de2b 16673783 problem in X11/LIBRARIES
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents:
diff changeset
    11
Easily reproduced with a resource file that #includes itself.
d5dacbb8de2b 16673783 problem in X11/LIBRARIES
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents:
diff changeset
    12
d5dacbb8de2b 16673783 problem in X11/LIBRARIES
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents:
diff changeset
    13
Limit is set to a include depth of 100 files, which should be enough
d5dacbb8de2b 16673783 problem in X11/LIBRARIES
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents:
diff changeset
    14
for all known use cases, but could be adjusted later if necessary.
d5dacbb8de2b 16673783 problem in X11/LIBRARIES
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents:
diff changeset
    15
d5dacbb8de2b 16673783 problem in X11/LIBRARIES
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents:
diff changeset
    16
Reported-by: Ilja Van Sprundel <[email protected]>
d5dacbb8de2b 16673783 problem in X11/LIBRARIES
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents:
diff changeset
    17
Signed-off-by: Alan Coopersmith <[email protected]>
d5dacbb8de2b 16673783 problem in X11/LIBRARIES
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents:
diff changeset
    18
Reviewed-by: Matthieu Herrb <[email protected]>
d5dacbb8de2b 16673783 problem in X11/LIBRARIES
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents:
diff changeset
    19
---
d5dacbb8de2b 16673783 problem in X11/LIBRARIES
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents:
diff changeset
    20
 src/Xrm.c |   24 +++++++++++++++---------
d5dacbb8de2b 16673783 problem in X11/LIBRARIES
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents:
diff changeset
    21
 1 file changed, 15 insertions(+), 9 deletions(-)
d5dacbb8de2b 16673783 problem in X11/LIBRARIES
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents:
diff changeset
    22
d5dacbb8de2b 16673783 problem in X11/LIBRARIES
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents:
diff changeset
    23
diff --git a/src/Xrm.c b/src/Xrm.c
d5dacbb8de2b 16673783 problem in X11/LIBRARIES
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents:
diff changeset
    24
index 3e29ab0..2c0c324 100644
d5dacbb8de2b 16673783 problem in X11/LIBRARIES
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents:
diff changeset
    25
--- a/src/Xrm.c
d5dacbb8de2b 16673783 problem in X11/LIBRARIES
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents:
diff changeset
    26
+++ b/src/Xrm.c
d5dacbb8de2b 16673783 problem in X11/LIBRARIES
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents:
diff changeset
    27
@@ -1088,13 +1088,15 @@ static void GetIncludeFile(
d5dacbb8de2b 16673783 problem in X11/LIBRARIES
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents:
diff changeset
    28
     XrmDatabase db,
d5dacbb8de2b 16673783 problem in X11/LIBRARIES
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents:
diff changeset
    29
     _Xconst char *base,
d5dacbb8de2b 16673783 problem in X11/LIBRARIES
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents:
diff changeset
    30
     _Xconst char *fname,
d5dacbb8de2b 16673783 problem in X11/LIBRARIES
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents:
diff changeset
    31
-    int fnamelen);
d5dacbb8de2b 16673783 problem in X11/LIBRARIES
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents:
diff changeset
    32
+    int fnamelen,
d5dacbb8de2b 16673783 problem in X11/LIBRARIES
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents:
diff changeset
    33
+    int depth);
d5dacbb8de2b 16673783 problem in X11/LIBRARIES
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents:
diff changeset
    34
 
d5dacbb8de2b 16673783 problem in X11/LIBRARIES
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents:
diff changeset
    35
 static void GetDatabase(
d5dacbb8de2b 16673783 problem in X11/LIBRARIES
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents:
diff changeset
    36
     XrmDatabase db,
d5dacbb8de2b 16673783 problem in X11/LIBRARIES
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents:
diff changeset
    37
     _Xconst char *str,
d5dacbb8de2b 16673783 problem in X11/LIBRARIES
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents:
diff changeset
    38
     _Xconst char *filename,
d5dacbb8de2b 16673783 problem in X11/LIBRARIES
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents:
diff changeset
    39
-    Bool doall)
d5dacbb8de2b 16673783 problem in X11/LIBRARIES
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents:
diff changeset
    40
+    Bool doall,
d5dacbb8de2b 16673783 problem in X11/LIBRARIES
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents:
diff changeset
    41
+    int depth)
d5dacbb8de2b 16673783 problem in X11/LIBRARIES
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents:
diff changeset
    42
 {
d5dacbb8de2b 16673783 problem in X11/LIBRARIES
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents:
diff changeset
    43
     char *rhs;
d5dacbb8de2b 16673783 problem in X11/LIBRARIES
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents:
diff changeset
    44
     char *lhs, lhs_s[DEF_BUFF_SIZE];
d5dacbb8de2b 16673783 problem in X11/LIBRARIES
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents:
diff changeset
    45
@@ -1204,7 +1206,8 @@ static void GetDatabase(
d5dacbb8de2b 16673783 problem in X11/LIBRARIES
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents:
diff changeset
    46
 		    } while (c != '"' && !is_EOL(bits));
d5dacbb8de2b 16673783 problem in X11/LIBRARIES
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents:
diff changeset
    47
 		    /* must have an ending " */
d5dacbb8de2b 16673783 problem in X11/LIBRARIES
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents:
diff changeset
    48
 		    if (c == '"')
d5dacbb8de2b 16673783 problem in X11/LIBRARIES
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents:
diff changeset
    49
-			GetIncludeFile(db, filename, fname, str - len - fname);
d5dacbb8de2b 16673783 problem in X11/LIBRARIES
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents:
diff changeset
    50
+			GetIncludeFile(db, filename, fname, str - len - fname,
d5dacbb8de2b 16673783 problem in X11/LIBRARIES
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents:
diff changeset
    51
+			    depth);
d5dacbb8de2b 16673783 problem in X11/LIBRARIES
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents:
diff changeset
    52
 		}
d5dacbb8de2b 16673783 problem in X11/LIBRARIES
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents:
diff changeset
    53
 	    }
d5dacbb8de2b 16673783 problem in X11/LIBRARIES
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents:
diff changeset
    54
 	    /* spin to next newline */
d5dacbb8de2b 16673783 problem in X11/LIBRARIES
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents:
diff changeset
    55
@@ -1545,7 +1548,7 @@ XrmPutLineResource(
d5dacbb8de2b 16673783 problem in X11/LIBRARIES
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents:
diff changeset
    56
 {
d5dacbb8de2b 16673783 problem in X11/LIBRARIES
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents:
diff changeset
    57
     if (!*pdb) *pdb = NewDatabase();
d5dacbb8de2b 16673783 problem in X11/LIBRARIES
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents:
diff changeset
    58
     _XLockMutex(&(*pdb)->linfo);
d5dacbb8de2b 16673783 problem in X11/LIBRARIES
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents:
diff changeset
    59
-    GetDatabase(*pdb, line, (char *)NULL, False);
d5dacbb8de2b 16673783 problem in X11/LIBRARIES
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents:
diff changeset
    60
+    GetDatabase(*pdb, line, (char *)NULL, False, 0);
d5dacbb8de2b 16673783 problem in X11/LIBRARIES
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents:
diff changeset
    61
     _XUnlockMutex(&(*pdb)->linfo);
d5dacbb8de2b 16673783 problem in X11/LIBRARIES
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents:
diff changeset
    62
 }
d5dacbb8de2b 16673783 problem in X11/LIBRARIES
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents:
diff changeset
    63
 
d5dacbb8de2b 16673783 problem in X11/LIBRARIES
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents:
diff changeset
    64
@@ -1557,7 +1560,7 @@ XrmGetStringDatabase(
d5dacbb8de2b 16673783 problem in X11/LIBRARIES
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents:
diff changeset
    65
 
d5dacbb8de2b 16673783 problem in X11/LIBRARIES
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents:
diff changeset
    66
     db = NewDatabase();
d5dacbb8de2b 16673783 problem in X11/LIBRARIES
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents:
diff changeset
    67
     _XLockMutex(&db->linfo);
d5dacbb8de2b 16673783 problem in X11/LIBRARIES
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents:
diff changeset
    68
-    GetDatabase(db, data, (char *)NULL, True);
d5dacbb8de2b 16673783 problem in X11/LIBRARIES
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents:
diff changeset
    69
+    GetDatabase(db, data, (char *)NULL, True, 0);
d5dacbb8de2b 16673783 problem in X11/LIBRARIES
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents:
diff changeset
    70
     _XUnlockMutex(&db->linfo);
d5dacbb8de2b 16673783 problem in X11/LIBRARIES
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents:
diff changeset
    71
     return db;
d5dacbb8de2b 16673783 problem in X11/LIBRARIES
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents:
diff changeset
    72
 }
d5dacbb8de2b 16673783 problem in X11/LIBRARIES
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents:
diff changeset
    73
@@ -1636,7 +1639,8 @@ GetIncludeFile(
d5dacbb8de2b 16673783 problem in X11/LIBRARIES
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents:
diff changeset
    74
     XrmDatabase db,
d5dacbb8de2b 16673783 problem in X11/LIBRARIES
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents:
diff changeset
    75
     _Xconst char *base,
d5dacbb8de2b 16673783 problem in X11/LIBRARIES
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents:
diff changeset
    76
     _Xconst char *fname,
d5dacbb8de2b 16673783 problem in X11/LIBRARIES
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents:
diff changeset
    77
-    int fnamelen)
d5dacbb8de2b 16673783 problem in X11/LIBRARIES
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents:
diff changeset
    78
+    int fnamelen,
d5dacbb8de2b 16673783 problem in X11/LIBRARIES
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents:
diff changeset
    79
+    int depth)
d5dacbb8de2b 16673783 problem in X11/LIBRARIES
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents:
diff changeset
    80
 {
d5dacbb8de2b 16673783 problem in X11/LIBRARIES
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents:
diff changeset
    81
     int len;
d5dacbb8de2b 16673783 problem in X11/LIBRARIES
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents:
diff changeset
    82
     char *str;
d5dacbb8de2b 16673783 problem in X11/LIBRARIES
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents:
diff changeset
    83
@@ -1644,6 +1648,8 @@ GetIncludeFile(
d5dacbb8de2b 16673783 problem in X11/LIBRARIES
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents:
diff changeset
    84
 
d5dacbb8de2b 16673783 problem in X11/LIBRARIES
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents:
diff changeset
    85
     if (fnamelen <= 0 || fnamelen >= BUFSIZ)
d5dacbb8de2b 16673783 problem in X11/LIBRARIES
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents:
diff changeset
    86
 	return;
d5dacbb8de2b 16673783 problem in X11/LIBRARIES
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents:
diff changeset
    87
+    if (depth >= MAXDBDEPTH)
d5dacbb8de2b 16673783 problem in X11/LIBRARIES
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents:
diff changeset
    88
+	return;
d5dacbb8de2b 16673783 problem in X11/LIBRARIES
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents:
diff changeset
    89
     if (*fname != '/' && base && (str = strrchr(base, '/'))) {
d5dacbb8de2b 16673783 problem in X11/LIBRARIES
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents:
diff changeset
    90
 	len = str - base + 1;
d5dacbb8de2b 16673783 problem in X11/LIBRARIES
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents:
diff changeset
    91
 	if (len + fnamelen >= BUFSIZ)
d5dacbb8de2b 16673783 problem in X11/LIBRARIES
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents:
diff changeset
    92
@@ -1657,7 +1663,7 @@ GetIncludeFile(
d5dacbb8de2b 16673783 problem in X11/LIBRARIES
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents:
diff changeset
    93
     }
d5dacbb8de2b 16673783 problem in X11/LIBRARIES
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents:
diff changeset
    94
     if (!(str = ReadInFile(realfname)))
d5dacbb8de2b 16673783 problem in X11/LIBRARIES
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents:
diff changeset
    95
 	return;
d5dacbb8de2b 16673783 problem in X11/LIBRARIES
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents:
diff changeset
    96
-    GetDatabase(db, str, realfname, True);
d5dacbb8de2b 16673783 problem in X11/LIBRARIES
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents:
diff changeset
    97
+    GetDatabase(db, str, realfname, True, depth + 1);
d5dacbb8de2b 16673783 problem in X11/LIBRARIES
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents:
diff changeset
    98
     Xfree(str);
d5dacbb8de2b 16673783 problem in X11/LIBRARIES
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents:
diff changeset
    99
 }
d5dacbb8de2b 16673783 problem in X11/LIBRARIES
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents:
diff changeset
   100
 
d5dacbb8de2b 16673783 problem in X11/LIBRARIES
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents:
diff changeset
   101
@@ -1673,7 +1679,7 @@ XrmGetFileDatabase(
d5dacbb8de2b 16673783 problem in X11/LIBRARIES
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents:
diff changeset
   102
 
d5dacbb8de2b 16673783 problem in X11/LIBRARIES
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents:
diff changeset
   103
     db = NewDatabase();
d5dacbb8de2b 16673783 problem in X11/LIBRARIES
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents:
diff changeset
   104
     _XLockMutex(&db->linfo);
d5dacbb8de2b 16673783 problem in X11/LIBRARIES
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents:
diff changeset
   105
-    GetDatabase(db, str, filename, True);
d5dacbb8de2b 16673783 problem in X11/LIBRARIES
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents:
diff changeset
   106
+    GetDatabase(db, str, filename, True, 0);
d5dacbb8de2b 16673783 problem in X11/LIBRARIES
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents:
diff changeset
   107
     _XUnlockMutex(&db->linfo);
d5dacbb8de2b 16673783 problem in X11/LIBRARIES
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents:
diff changeset
   108
     Xfree(str);
d5dacbb8de2b 16673783 problem in X11/LIBRARIES
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents:
diff changeset
   109
     return db;
d5dacbb8de2b 16673783 problem in X11/LIBRARIES
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents:
diff changeset
   110
@@ -1697,7 +1703,7 @@ XrmCombineFileDatabase(
d5dacbb8de2b 16673783 problem in X11/LIBRARIES
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents:
diff changeset
   111
     } else
d5dacbb8de2b 16673783 problem in X11/LIBRARIES
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents:
diff changeset
   112
 	db = NewDatabase();
d5dacbb8de2b 16673783 problem in X11/LIBRARIES
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents:
diff changeset
   113
     _XLockMutex(&db->linfo);
d5dacbb8de2b 16673783 problem in X11/LIBRARIES
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents:
diff changeset
   114
-    GetDatabase(db, str, filename, True);
d5dacbb8de2b 16673783 problem in X11/LIBRARIES
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents:
diff changeset
   115
+    GetDatabase(db, str, filename, True, 0);
d5dacbb8de2b 16673783 problem in X11/LIBRARIES
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents:
diff changeset
   116
     _XUnlockMutex(&db->linfo);
d5dacbb8de2b 16673783 problem in X11/LIBRARIES
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents:
diff changeset
   117
     Xfree(str);
d5dacbb8de2b 16673783 problem in X11/LIBRARIES
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents:
diff changeset
   118
     if (!override)
d5dacbb8de2b 16673783 problem in X11/LIBRARIES
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents:
diff changeset
   119
-- 
d5dacbb8de2b 16673783 problem in X11/LIBRARIES
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents:
diff changeset
   120
1.7.9.2
d5dacbb8de2b 16673783 problem in X11/LIBRARIES
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents:
diff changeset
   121
d5dacbb8de2b 16673783 problem in X11/LIBRARIES
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents:
diff changeset
   122
From f94dc4a99aa1845c6a25826e99e11aaa4fff78eb Mon Sep 17 00:00:00 2001
d5dacbb8de2b 16673783 problem in X11/LIBRARIES
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents:
diff changeset
   123
From: Alan Coopersmith <[email protected]>
d5dacbb8de2b 16673783 problem in X11/LIBRARIES
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents:
diff changeset
   124
Date: Sat, 2 Mar 2013 12:39:58 -0800
d5dacbb8de2b 16673783 problem in X11/LIBRARIES
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents:
diff changeset
   125
Subject: [PATCH:libX11 23/38] Unbounded recursion in _XimParseStringFile()
d5dacbb8de2b 16673783 problem in X11/LIBRARIES
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents:
diff changeset
   126
 when parsing include files [CVE-2013-2004 2/2]
d5dacbb8de2b 16673783 problem in X11/LIBRARIES
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents:
diff changeset
   127
d5dacbb8de2b 16673783 problem in X11/LIBRARIES
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents:
diff changeset
   128
parseline() can call _XimParseStringFile() which can call parseline()
d5dacbb8de2b 16673783 problem in X11/LIBRARIES
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents:
diff changeset
   129
which can call _XimParseStringFile() which can call parseline() ....
d5dacbb8de2b 16673783 problem in X11/LIBRARIES
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents:
diff changeset
   130
eventually causing recursive stack overflow and crash.
d5dacbb8de2b 16673783 problem in X11/LIBRARIES
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents:
diff changeset
   131
d5dacbb8de2b 16673783 problem in X11/LIBRARIES
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents:
diff changeset
   132
Limit is set to a include depth of 100 files, which should be enough
d5dacbb8de2b 16673783 problem in X11/LIBRARIES
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents:
diff changeset
   133
for all known use cases, but could be adjusted later if necessary.
d5dacbb8de2b 16673783 problem in X11/LIBRARIES
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents:
diff changeset
   134
d5dacbb8de2b 16673783 problem in X11/LIBRARIES
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents:
diff changeset
   135
Reported-by: Ilja Van Sprundel <[email protected]>
d5dacbb8de2b 16673783 problem in X11/LIBRARIES
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents:
diff changeset
   136
Signed-off-by: Alan Coopersmith <[email protected]>
d5dacbb8de2b 16673783 problem in X11/LIBRARIES
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents:
diff changeset
   137
Reviewed-by: Matthieu Herrb <[email protected]>
d5dacbb8de2b 16673783 problem in X11/LIBRARIES
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents:
diff changeset
   138
---
d5dacbb8de2b 16673783 problem in X11/LIBRARIES
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents:
diff changeset
   139
 modules/im/ximcp/imLcPrs.c |   20 +++++++++++++++++---
d5dacbb8de2b 16673783 problem in X11/LIBRARIES
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents:
diff changeset
   140
 1 file changed, 17 insertions(+), 3 deletions(-)
d5dacbb8de2b 16673783 problem in X11/LIBRARIES
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents:
diff changeset
   141
d5dacbb8de2b 16673783 problem in X11/LIBRARIES
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents:
diff changeset
   142
diff --git a/modules/im/ximcp/imLcPrs.c b/modules/im/ximcp/imLcPrs.c
d5dacbb8de2b 16673783 problem in X11/LIBRARIES
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents:
diff changeset
   143
index 4e54385..4c7d6f0 100644
d5dacbb8de2b 16673783 problem in X11/LIBRARIES
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents:
diff changeset
   144
--- a/modules/im/ximcp/imLcPrs.c
d5dacbb8de2b 16673783 problem in X11/LIBRARIES
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents:
diff changeset
   145
+++ b/modules/im/ximcp/imLcPrs.c
d5dacbb8de2b 16673783 problem in X11/LIBRARIES
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents:
diff changeset
   146
@@ -56,6 +56,8 @@ extern int _Xmbstoutf8(
d5dacbb8de2b 16673783 problem in X11/LIBRARIES
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents:
diff changeset
   147
     int		len
d5dacbb8de2b 16673783 problem in X11/LIBRARIES
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents:
diff changeset
   148
 );
d5dacbb8de2b 16673783 problem in X11/LIBRARIES
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents:
diff changeset
   149
 
d5dacbb8de2b 16673783 problem in X11/LIBRARIES
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents:
diff changeset
   150
+static void parsestringfile(FILE *fp, Xim im, int depth);
d5dacbb8de2b 16673783 problem in X11/LIBRARIES
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents:
diff changeset
   151
+
d5dacbb8de2b 16673783 problem in X11/LIBRARIES
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents:
diff changeset
   152
 /*
d5dacbb8de2b 16673783 problem in X11/LIBRARIES
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents:
diff changeset
   153
  *	Parsing File Format:
d5dacbb8de2b 16673783 problem in X11/LIBRARIES
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents:
diff changeset
   154
  *
d5dacbb8de2b 16673783 problem in X11/LIBRARIES
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents:
diff changeset
   155
@@ -423,7 +425,8 @@ static int
d5dacbb8de2b 16673783 problem in X11/LIBRARIES
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents:
diff changeset
   156
 parseline(
d5dacbb8de2b 16673783 problem in X11/LIBRARIES
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents:
diff changeset
   157
     FILE *fp,
d5dacbb8de2b 16673783 problem in X11/LIBRARIES
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents:
diff changeset
   158
     Xim   im,
d5dacbb8de2b 16673783 problem in X11/LIBRARIES
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents:
diff changeset
   159
-    char* tokenbuf)
d5dacbb8de2b 16673783 problem in X11/LIBRARIES
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents:
diff changeset
   160
+    char* tokenbuf,
d5dacbb8de2b 16673783 problem in X11/LIBRARIES
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents:
diff changeset
   161
+    int   depth)
d5dacbb8de2b 16673783 problem in X11/LIBRARIES
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents:
diff changeset
   162
 {
d5dacbb8de2b 16673783 problem in X11/LIBRARIES
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents:
diff changeset
   163
     int token;
d5dacbb8de2b 16673783 problem in X11/LIBRARIES
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents:
diff changeset
   164
     DTModifier modifier_mask;
d5dacbb8de2b 16673783 problem in X11/LIBRARIES
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents:
diff changeset
   165
@@ -470,11 +473,13 @@ parseline(
d5dacbb8de2b 16673783 problem in X11/LIBRARIES
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents:
diff changeset
   166
                 goto error;
d5dacbb8de2b 16673783 problem in X11/LIBRARIES
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents:
diff changeset
   167
             if ((filename = TransFileName(im, tokenbuf)) == NULL)
d5dacbb8de2b 16673783 problem in X11/LIBRARIES
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents:
diff changeset
   168
                 goto error;
d5dacbb8de2b 16673783 problem in X11/LIBRARIES
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents:
diff changeset
   169
+            if (++depth > 100)
d5dacbb8de2b 16673783 problem in X11/LIBRARIES
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents:
diff changeset
   170
+                goto error;
d5dacbb8de2b 16673783 problem in X11/LIBRARIES
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents:
diff changeset
   171
             infp = _XFopenFile(filename, "r");
d5dacbb8de2b 16673783 problem in X11/LIBRARIES
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents:
diff changeset
   172
                 Xfree(filename);
d5dacbb8de2b 16673783 problem in X11/LIBRARIES
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents:
diff changeset
   173
             if (infp == NULL)
d5dacbb8de2b 16673783 problem in X11/LIBRARIES
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents:
diff changeset
   174
                 goto error;
d5dacbb8de2b 16673783 problem in X11/LIBRARIES
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents:
diff changeset
   175
-            _XimParseStringFile(infp, im);
d5dacbb8de2b 16673783 problem in X11/LIBRARIES
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents:
diff changeset
   176
+            parsestringfile(infp, im, depth);
d5dacbb8de2b 16673783 problem in X11/LIBRARIES
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents:
diff changeset
   177
             fclose(infp);
d5dacbb8de2b 16673783 problem in X11/LIBRARIES
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents:
diff changeset
   178
             return (0);
d5dacbb8de2b 16673783 problem in X11/LIBRARIES
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents:
diff changeset
   179
 	} else if ((token == KEY) && (strcmp("None", tokenbuf) == 0)) {
d5dacbb8de2b 16673783 problem in X11/LIBRARIES
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents:
diff changeset
   180
@@ -668,6 +673,15 @@ _XimParseStringFile(
d5dacbb8de2b 16673783 problem in X11/LIBRARIES
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents:
diff changeset
   181
     FILE *fp,
d5dacbb8de2b 16673783 problem in X11/LIBRARIES
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents:
diff changeset
   182
     Xim   im)
d5dacbb8de2b 16673783 problem in X11/LIBRARIES
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents:
diff changeset
   183
 {
d5dacbb8de2b 16673783 problem in X11/LIBRARIES
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents:
diff changeset
   184
+    parsestringfile(fp, im, 0);
d5dacbb8de2b 16673783 problem in X11/LIBRARIES
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents:
diff changeset
   185
+}
d5dacbb8de2b 16673783 problem in X11/LIBRARIES
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents:
diff changeset
   186
+
d5dacbb8de2b 16673783 problem in X11/LIBRARIES
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents:
diff changeset
   187
+static void
d5dacbb8de2b 16673783 problem in X11/LIBRARIES
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents:
diff changeset
   188
+parsestringfile(
d5dacbb8de2b 16673783 problem in X11/LIBRARIES
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents:
diff changeset
   189
+    FILE *fp,
d5dacbb8de2b 16673783 problem in X11/LIBRARIES
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents:
diff changeset
   190
+    Xim   im,
d5dacbb8de2b 16673783 problem in X11/LIBRARIES
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents:
diff changeset
   191
+    int   depth)
d5dacbb8de2b 16673783 problem in X11/LIBRARIES
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents:
diff changeset
   192
+{
d5dacbb8de2b 16673783 problem in X11/LIBRARIES
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents:
diff changeset
   193
     char tb[8192];
d5dacbb8de2b 16673783 problem in X11/LIBRARIES
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents:
diff changeset
   194
     char* tbp;
d5dacbb8de2b 16673783 problem in X11/LIBRARIES
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents:
diff changeset
   195
     struct stat st;
d5dacbb8de2b 16673783 problem in X11/LIBRARIES
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents:
diff changeset
   196
@@ -678,7 +692,7 @@ _XimParseStringFile(
d5dacbb8de2b 16673783 problem in X11/LIBRARIES
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents:
diff changeset
   197
 	else tbp = malloc (size);
d5dacbb8de2b 16673783 problem in X11/LIBRARIES
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents:
diff changeset
   198
 
d5dacbb8de2b 16673783 problem in X11/LIBRARIES
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents:
diff changeset
   199
 	if (tbp != NULL) {
d5dacbb8de2b 16673783 problem in X11/LIBRARIES
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents:
diff changeset
   200
-	    while (parseline(fp, im, tbp) >= 0) {}
d5dacbb8de2b 16673783 problem in X11/LIBRARIES
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents:
diff changeset
   201
+	    while (parseline(fp, im, tbp, depth) >= 0) {}
d5dacbb8de2b 16673783 problem in X11/LIBRARIES
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents:
diff changeset
   202
 	    if (tbp != tb) free (tbp);
d5dacbb8de2b 16673783 problem in X11/LIBRARIES
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents:
diff changeset
   203
 	}
d5dacbb8de2b 16673783 problem in X11/LIBRARIES
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents:
diff changeset
   204
     }
d5dacbb8de2b 16673783 problem in X11/LIBRARIES
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents:
diff changeset
   205
-- 
d5dacbb8de2b 16673783 problem in X11/LIBRARIES
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents:
diff changeset
   206
1.7.9.2
d5dacbb8de2b 16673783 problem in X11/LIBRARIES
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents:
diff changeset
   207