Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: [PATCH 3/3] jp: Add `dupstring()` fallback to `zhtricat()`
- X-seq: zsh-workers 42277
- From: Joey Pabalinas <joeypabalinas@xxxxxxxxx>
- To: schaefer@xxxxxxxxxxxxxxxx
- Subject: Re: [PATCH 3/3] jp: Add `dupstring()` fallback to `zhtricat()`
- Date: Sun, 14 Jan 2018 05:29:59 -1000
- Cc: dana@xxxxxxx, zsh-workers@xxxxxxx
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=AQvHg6oiQsQXPWcvgeQJzRJ9ID1/A2mwpqa9yiA1ExA=; b=QDT4Y+6/pyWszsAodW5tYalUJMQPg3L3iSlc99rHdHFesAZIDKP6OlWHQCZZhnZXm5 KJ6/yZTYVAj77aK7ZO6+8v2BEzhYkpKPC9KvUDjgLtWhv5Ig8QiI2fjfZrs+EObGSXOi tUJUnJeki/tFN5UlucAUC4Pbz9egDv0K7CC0dQInrzTtZ21ETMXaGUzGne8YdDtiHA1z xn54l4o1LzBIK0faNOLOQE7UnHuG5WfqgkX7y0YCwFdZ8/HlisB9ysI/+s+77ZPLrPqu 0ievNUThF15iRATKsfpx7JcWHKXGRlcwxN2Pz7vH30CkIpE3ftHdfpdvV2jfp5H/R1l1 6w6Q==
- In-reply-to: <20180114152344.12018-4-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> <20180114152344.12018-4-joeypabalinas@gmail.com>
On Sun, Jan 14, 2018 at 05:23:44AM -1000, Joey Pabalinas wrote:
> Add `dupstring()` fallback machanism to guard against NULL derefs
> in 3-argument concat function.
I am not 100% sure about this patch, so I split it off along with
the error message changes; feel free to drop individual patches or
suggest improvements.
On Sun, Jan 14, 2018 at 05:23:44AM -1000, Joey Pabalinas wrote:
> 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
--
Joey Pabalinas
Attachment:
signature.asc
Description: PGP signature
Messages sorted by:
Reverse Date,
Date,
Thread,
Author