[patch] Fix for heap overflow in wscanf (BZ 16618)

Andreas Schwab schwab@suse.de
Mon Feb 2 10:03:00 GMT 2015


Paul Pluzhnikov <ppluzhnikov@google.com> writes:

> diff --git a/stdio-common/vfscanf.c b/stdio-common/vfscanf.c
> index cd129a8..71cba38 100644
> --- a/stdio-common/vfscanf.c
> +++ b/stdio-common/vfscanf.c
> @@ -274,9 +274,17 @@ _IO_vfscanf_internal (_IO_FILE *s, const char *format, _IO_va_list argptr,
>  	  CHAR_T *old = wp;						    \
>  	  size_t newsize = (UCHAR_MAX + 1 > 2 * wpmax			    \
>  			    ? UCHAR_MAX + 1 : 2 * wpmax);		    \
> -	  if (use_malloc || !__libc_use_alloca (newsize))		    \
> +	  if (__glibc_unlikely (wpmax > SIZE_MAX / 2)			    \
> +	      || __glibc_unlikely (newsize > SIZE_MAX / sizeof (CHAR_T)))   \
>  	    {								    \
> -	      wp = realloc (use_malloc ? wp : NULL, newsize);		    \
> +	      if (use_malloc)						    \
> +	    	free (old);						    \
> +	      done = EOF;						    \
> +	      goto errout;						    \
> +	    }								    \

You should set errno here.

Andreas.

-- 
Andreas Schwab, SUSE Labs, schwab@suse.de
GPG Key fingerprint = 0196 BAD8 1CE9 1970 F4BE  1748 E4D4 88E3 0EEA B9D7
"And now for something completely different."



More information about the Libc-alpha mailing list