Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
PATCH: don't increment a null pointer in set -A
- X-seq: zsh-workers 42601
- From: Oliver Kiddle <okiddle@xxxxxxxxxxx>
- To: Zsh workers <zsh-workers@xxxxxxx>
- Subject: PATCH: don't increment a null pointer in set -A
- Date: Fri, 06 Apr 2018 18:06:07 +0200
- Authentication-results: amavisd4.gkg.net (amavisd-new); dkim=pass (2048-bit key) header.d=yahoo.co.uk
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.co.uk; s=s2048; t=1523030768; bh=mgwL/h97+bvhafQAUVCYRVx4hb+CTi+LG4OMryztGc8=; h=From:To:Subject:Date:From:Subject; b=iC2b5e6b7PUZulFnhahYgUtkhOdPV3XwatidM0LonM+bMbSM6b7LV3hkzsLTUtGHF2xsUt++/ds6VR2Tqt4o1iinvde6qMyikYooaPRKERHvOZOmnLX1Jxti1uPdLvBK0eK/SYjSBlYCHGw+q/DkW6IwCL/+3L4Ct2ibjfHLaX/zqR9iA+UkYncAOn7tRSvCEwiDFyQts+4hmK5Ob8rymMxm84ErHA2sGTN7XRpJ/+DPx1BpAQEtRFylXxNXh9iCeMswQSzNpvdSGrd+rl6CX6NPnyPeX4OR/YvtpnrvlCRy78Z6oqwWWCMeqSi8TsHiV/B4yVkCNse6KVP6o/P89Q==
- 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
In coverity CID 1255831, it warns about this code which handles set -A
and set +A. There's no actual bug here but the following change is more
efficient (thanks to arrlen_gt) and makes the code somewhat cleaner at
least in my opinion. In the case of set -A, we assign a to NULL and then
increment it with each loop. Incrementing a NULL pointer is harmless but
still a bit icky.
Unfortunately, coverity will probably still complain about this because
it can't connect the fact that (!*args) will only ever be true when a
wasn't/isn't null.
Oliver
diff --git a/Src/builtin.c b/Src/builtin.c
index fb59738f3..73cfe7ad1 100644
--- a/Src/builtin.c
+++ b/Src/builtin.c
@@ -695,13 +695,11 @@ bin_set(char *nam, char **args, UNUSED(Options ops), UNUSED(int func))
char **a = NULL, **y;
int len = arrlen(args);
- if (array < 0 && (a = getaparam(arrayname))) {
- int al = arrlen(a);
-
- if (al > len)
- len = al;
+ if (array < 0 && (a = getaparam(arrayname)) && arrlen_gt(a, len)) {
+ a += len;
+ len += arrlen(a);
}
- for (x = y = zalloc((len + 1) * sizeof(char *)); len--; a++) {
+ for (x = y = zalloc((len + 1) * sizeof(char *)); len--;) {
if (!*args)
args = a;
*y++ = ztrdup(*args++);
Messages sorted by:
Reverse Date,
Date,
Thread,
Author