Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: [PATCH 3/3] jp: Add `dupstring()` fallback to `zhtricat()`



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