Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
[PATCH 3/3] jp: Add `dupstring()` fallback to `zhtricat()`
- X-seq: zsh-workers 42276
- From: Joey Pabalinas <joeypabalinas@xxxxxxxxx>
- To: schaefer@xxxxxxxxxxxxxxxx
- Subject: [PATCH 3/3] jp: Add `dupstring()` fallback to `zhtricat()`
- Date: Sun, 14 Jan 2018 05:23:44 -1000
- Cc: dana@xxxxxxx, zsh-workers@xxxxxxx, Joey Pabalinas <joeypabalinas@xxxxxxxxx>
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=1pBdquXwTKE6tTMVcTeuoGemhPIA4m0V/uTycRMMqpc=; b=Eb8M+yeqO+vtCNriHJ8XoqWXup4yQZ/raWvGPK1oFFYhkvzN/v7G29faqzmRtAjHRi S8CgIdrH2yixjQqtE5SFnjNMtdaZqdwov5I1U0/6YPIC6R9JPFvQG+vOqGnrkcxxRSIH GESfIO0jQruujeYzIXScm537ou27hNCEzE00UM4w6fKNHKkhWEoDF13xqxl3Z1GPu+kJ psbFvXpUMmRk5OD3zWMTvMSqQYP4OD2ORI68tXciI6Gz6qNTbr0fq12PdGhiXaSrBNZE hl9j2PVT2+4inOwK97Ls2ZKVomowAikPzVeHoEO9ZQ/oCfK/jVvDlu/wdJN04XBDuLBq d+QA==
- In-reply-to: <20180114152344.12018-1-joeypabalinas@gmail.com>
- 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
- References: <20180114152344.12018-1-joeypabalinas@gmail.com>
Add `dupstring()` fallback machanism to guard against NULL derefs
in 3-argument concat function.
Signed-off-by: Joey Pabalinas <joeypabalinas@xxxxxxxxx>
1 file changed, 9 insertions(+), 2 deletions(-)
diff --git a/Src/string.c b/Src/string.c
index 038624d65a9f533494..df7e932061dbfbaab2 100644
--- a/Src/string.c
+++ b/Src/string.c
@@ -126,9 +126,16 @@ mod_export char *
zhtricat(char const *s1, char const *s2, char const *s3)
{
char *ptr;
- size_t l1 = strlen(s1);
- size_t l2 = strlen(s2);
+ size_t l1, l2;
+ /* String duplicate fallback to prevent NULL derefs */
+ if (!s1 && !s2)
+ return dupstring(s3);
+ if (!s1)
+ l1 = 0, s1 = s2;
+ else
+ l1 = strlen(s1);
+ l2 = strlen(s2);
ptr = (char *)zhalloc(l1 + l2 + strlen(s3) + 1);
strcpy(ptr, s1);
strcpy(ptr + l1, s2);
--
2.15.1
Messages sorted by:
Reverse Date,
Date,
Thread,
Author