aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Eggert <eggert@cs.ucla.edu>2017-10-22 10:00:57 +0200
committerAurelien Jarno <aurelien@aurel32.net>2017-12-02 22:58:11 +0100
commit94825c8924b80518214ad9e3ca1f6589f209592c (patch)
tree52f689273f95f904bfb3d63113ff5c20d1175088
parent1e53b88296dc95d325d6073910a33dca851b6bc4 (diff)
downloadglibc-94825c8924b80518214ad9e3ca1f6589f209592c.tar
glibc-94825c8924b80518214ad9e3ca1f6589f209592c.tar.gz
glibc-94825c8924b80518214ad9e3ca1f6589f209592c.tar.bz2
glibc-94825c8924b80518214ad9e3ca1f6589f209592c.zip
glob: Fix buffer overflow during GLOB_TILDE unescaping [BZ #22332]
(cherry picked from commit a159b53fa059947cc2548e3b0d5bdcf7b9630ba8)
-rw-r--r--ChangeLog6
-rw-r--r--NEWS4
-rw-r--r--posix/glob.c4
3 files changed, 12 insertions, 2 deletions
diff --git a/ChangeLog b/ChangeLog
index 01a1e99d83..77eea1e024 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2017-10-22 Paul Eggert <eggert@cs.ucla.edu>
+
+ [BZ #22332]
+ * posix/glob.c (__glob): Fix buffer overflow during GLOB_TILDE
+ unescaping.
+
2017-10-21 Florian Weimer <fweimer@redhat.com>
* posix/Makefile (tests): Add tst-glob-tilde.
diff --git a/NEWS b/NEWS
index a70d21eb40..0531dfa9c6 100644
--- a/NEWS
+++ b/NEWS
@@ -30,6 +30,10 @@ Security related changes:
processing, leading to a memory leak and, potentially, to a denial
of service.
+* The glob function, when invoked with GLOB_TILDE and without
+ GLOB_NOESCAPE, could write past the end of a buffer while
+ unescaping user names. Reported by Tim Rühsen.
+
The following bugs are resolved with this release:
[20790] Fix rpcgen buffer overrun
diff --git a/posix/glob.c b/posix/glob.c
index 026bc063d3..f3fa807700 100644
--- a/posix/glob.c
+++ b/posix/glob.c
@@ -863,11 +863,11 @@ glob (const char *pattern, int flags, int (*errfunc) (const char *, int),
char *p = mempcpy (newp, dirname + 1,
unescape - dirname - 1);
char *q = unescape;
- while (*q != '\0')
+ while (q != end_name)
{
if (*q == '\\')
{
- if (q[1] == '\0')
+ if (q + 1 == end_name)
{
/* "~fo\\o\\" unescape to user_name "foo\\",
but "~fo\\o\\/" unescape to user_name