[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
Wed Feb 24 18:12:22 CET 2021



Merge request https://gitlab.com/gnutls/gnutls/-/merge_requests/1392 was reviewed by Stanislav Židek

--
  
Stanislav Židek started a new discussion on lib/x509/crl.c: https://gitlab.com/gnutls/gnutls/-/merge_requests/1392#note_516422512

> -		    gnutls_realloc_fast(*crls,
> -					sizeof(gnutls_x509_crl_t) * init);
> +		*crls = _gnutls_reallocarray_fast(*crls, init,

If I understand correctly, the `_fast` version does also frees the original array if reallocation fails. What I don't fully understand is why e.g. this line uses `_gnutls_reallocarray_fast`, but line 1265 does not. Could you clarify?

--
  
Stanislav Židek started a new discussion on lib/x509/pkcs12.c: https://gitlab.com/gnutls/gnutls/-/merge_requests/1392#note_516422515

> -						++(*chain_len));
> +			*chain = _gnutls_reallocarray_fast(*chain,
> +							   ++(*chain_len),

This is inconsistent with other places that do `X + 1` most of the time (instead of `++X`). Shall we make it consistent?

--
  
Stanislav Židek started a new discussion on lib/x509/ocsp.c: https://gitlab.com/gnutls/gnutls/-/merge_requests/1392#note_516422519

> -			new_ocsps = gnutls_realloc(*ocsps, (*size + 1)*sizeof(gnutls_ocsp_resp_t));
> +			new_ocsps = _gnutls_reallocarray(*ocsps,
> +							 *size + 1,

One generic and theoretical question: I was told at the university that allocations are pretty expensive operations and we should not use them to expand arrays only by one item. I bet there is a pretty good reason for this in multiple places here, could you perhaps explain?

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

> -					 sizeof(certs_st));
> +	res->certs = _gnutls_reallocarray_fast(res->certs,
> +					       1 + res->ncerts,

Inconsisten with the rest of the code here and on line 59 - `1 + X` vs. `X + 1`.


-- 
Reply to this email directly or view it on GitLab: https://gitlab.com/gnutls/gnutls/-/merge_requests/1392
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/20210224/d4d70382/attachment-0001.html>


More information about the Gnutls-devel mailing list