[gnutls-devel] GnuTLS | build: avoid potential integer overflow in array allocation (!1392)

Read-only notification of GnuTLS library development activities gnutls-devel at lists.gnutls.org
Sun Feb 28 12:00:46 CET 2021




Stanislav Židek commented on a discussion on lib/cert-cred.c: https://gitlab.com/gnutls/gnutls/-/merge_requests/1392#note_518757353

>  				       int nr)
>  {
> -	res->sorted_cert_idx = gnutls_realloc_fast(res->sorted_cert_idx,
> -						(1 + res->ncerts) *
> -						sizeof(unsigned int));
> +	res->sorted_cert_idx = _gnutls_reallocarray_fast(res->sorted_cert_idx,
> +							 1 + res->ncerts,
> +							 sizeof(unsigned int));
>  	if (res->sorted_cert_idx == NULL)
>  		return gnutls_assert_val(GNUTLS_E_MEMORY_ERROR);
>  
> -	res->certs = gnutls_realloc_fast(res->certs,
> -					 (1 + res->ncerts) *
> -					 sizeof(certs_st));
> +	res->certs = _gnutls_reallocarray_fast(res->certs,
> +					       1 + res->ncerts,

Is there a reason why `1 + res->ncerts` is better than `res->ncerts + 1`?

-- 
Reply to this email directly or view it on GitLab: https://gitlab.com/gnutls/gnutls/-/merge_requests/1392#note_518757353
You're receiving this email because of your account on gitlab.com.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.gnupg.org/pipermail/gnutls-devel/attachments/20210228/4a7119a5/attachment-0001.html>


More information about the Gnutls-devel mailing list