Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
PATCH: Stack-based buffer overflow in gen_matches_files() at compctl.c
- X-seq: zsh-workers 42519
- From: Oliver Kiddle <okiddle@xxxxxxxxxxx>
- To: Zsh workers <zsh-workers@xxxxxxx>
- Subject: PATCH: Stack-based buffer overflow in gen_matches_files() at compctl.c
- Date: Sat, 24 Mar 2018 14:02:38 +0100
- Authentication-results: amavisd4.gkg.net (amavisd-new); dkim=fail (2048-bit key) reason="fail (body has been altered)" header.d=yahoo.co.uk
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.co.uk; s=s2048; t=1521899926; bh=vApPHHm9YpvR7LhavlokzzU0PtOxoF/o9Cm5v5YfESg=; h=From:To:Subject:Date:From:Subject; b=ZEZd34UoOS9ZHUkkZE9Ec0RUfqioS3VCo7SkwNNxLEmmcRjJYSU31XFJXxivgO7yt65PyGX3B4HAlmKbRAfjWx7j9Bp0ds3TXslCp31XFodrKe+rVFP7cNMweziAWciI7ZwUmlQjEl3IQggqDSKEbt1hUY13q+0vHRPj4Isd+qCiHCZ4ng1PFnM3GbiSpMVfH6GMBQ7ZfeB9KBm+bVl1VvV9dw/sLx/e8fUmAZaqsqcoytkAKzx+FZs/wjXBbPokwuP6su0FDOqyUaKBMXm5dMYc0PZpdhpQ1d/WsVorY3pH+lcicRY4/jkLmgIREc833Gr8ukFZyWIYD51wO02Vkg==
- List-help: <mailto:zsh-workers-help@zsh.org>
- List-id: Zsh Workers List <zsh-workers.zsh.org>
- List-post: <mailto:zsh-workers@zsh.org>
- List-unsubscribe: <mailto:zsh-workers-unsubscribe@zsh.org>
- Mailing-list: contact zsh-workers-help@xxxxxxx; run by ezmlm
compctl.c:gen_matches_files() declares a local PATH_MAX-sized buffer
which is used for storing the completion prefix along with completion
candidate directories. It doesn't check that the current path actually
fits into the buffer, however. This bug corresponds to CVE-2018-1083 and
was reported off-list.
The patch adds a check in three places. This is tricky to test. I've
managed to check all three branches - it now drops the completion
candidate from consideration. But it would be good to have some more
eyes on this. In particular, might any of the tests be off-by-one?
Note that this issue only affects code that the vast majority of users
wouldn't exercise. In a minimally configured zsh setup (using compinit)
filename completion is handled by different code.
Oliver
diff --git a/Src/Zle/compctl.c b/Src/Zle/compctl.c
index e9d165780..87d13afc1 100644
--- a/Src/Zle/compctl.c
+++ b/Src/Zle/compctl.c
@@ -2176,6 +2176,8 @@ gen_matches_files(int dirs, int execs, int all)
if (prpre && *prpre) {
pathpref = dupstring(prpre);
unmetafy(pathpref, &pathpreflen);
+ if (pathpreflen > PATH_MAX)
+ return;
/* system needs NULL termination, not provided by unmetafy */
pathpref[pathpreflen] = '\0';
} else {
@@ -2218,6 +2220,8 @@ gen_matches_files(int dirs, int execs, int all)
* the path buffer by appending the filename. */
ums = dupstring(n);
unmetafy(ums, ¨en);
+ if (umlen + pathpreflen + 1 > PATH_MAX)
+ continue;
memcpy(q, ums, umlen);
q[umlen] = '\0';
/* And do the stat. */
@@ -2232,6 +2236,8 @@ gen_matches_files(int dirs, int execs, int all)
/* We have to test for a path suffix. */
int o = strlen(p), tt;
+ if (o + strlen(psuf) > PATH_MAX)
+ continue;
/* Append it to the path buffer. */
strcpy(p + o, psuf);
Messages sorted by:
Reverse Date,
Date,
Thread,
Author