[OpenWrt-Devel] [PATCH 5/6] uclient-utils: Handle memory allocation failure for url file name

John Crispin john at phrozen.org
Sun Feb 18 05:19:03 EST 2018



On 18/02/18 04:36, Tobias Schramm wrote:
> Signed-off-by: Tobias Schramm <tobleminer at gmail.com>
> ---
>   uclient-utils.c | 8 ++++++--
>   1 file changed, 6 insertions(+), 2 deletions(-)
>
> diff --git a/uclient-utils.c b/uclient-utils.c
> index a375eea..ee0f8e8 100644
> --- a/uclient-utils.c
> +++ b/uclient-utils.c
> @@ -177,8 +177,12 @@ char *uclient_get_url_filename(const char *url, const char *default_name)
>   	str++;
>   	len -= str - url;
>   
> -	if (len > 0)
> -		return strncpy(calloc(1, len + 1), str, len);
> +	if (len > 0) {
> +		char *fname = calloc(1, len + 1);
missing blank line  ...

     John

> +		if(!fname)
> +			return NULL;
>   
> +		return strncpy(fname, str, len);
> +	}
>   	return strdup(default_name);
>   }
_______________________________________________
openwrt-devel mailing list
openwrt-devel at lists.openwrt.org
https://lists.openwrt.org/cgi-bin/mailman/listinfo/openwrt-devel


More information about the openwrt-devel mailing list