<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">
<html lang="en">
<head>
<meta content="text/html; charset=US-ASCII" http-equiv="Content-Type">
<title>
GitLab
</title>


<style>img {
max-width: 100%; height: auto;
}
</style>
</head>
<body>
<div class="content">

<p class="details" style="font-style: italic; color: #666;">
<a href="https://gitlab.com/dueno">Daiki Ueno</a> created an issue <a href="https://gitlab.com/gnutls/gnutls/-/issues/1179">#1179</a>:
</p>
<div></div>
<p dir="auto">As mentioned in the <a href="https://gitlab.com/gnutls/gnutls/-/merge_requests/1379#note_493204236" data-original="comment" data-link="true" data-link-reference="true" data-project="179611" data-merge-request="84229636" data-project-path="gnutls/gnutls" data-iid="1379" data-mr-title="Verify that cert_list_size > 0 and cert_list != NULL" data-reference-type="merge_request" data-container="body" data-placement="top" title="" class="gfm gfm-merge_request">comment</a>, there are several occasions where arrays are allocated with <code>gnutls_malloc</code> without proper overflow checks:</p>
<pre class="code highlight js-syntax-highlight console" lang="console" v-pre="true"><code><span id="LC1" class="line" lang="console"><span class="go">git grep -E 'gnutls_malloc(\(sizeof\(.*\) *\* *.*\)|\(.* *\* *sizeof\(.*\))</span></span>
<span id="LC2" class="line" lang="console"><span class="gp">cert-cred-x509.c:       pcerts = gnutls_malloc(sizeof(gnutls_pcert_st) * count);</span></span>
<span id="LC3" class="line" lang="console"><span class="go">cert-cred-x509.c:       ccert = gnutls_malloc(sizeof(*ccert)*MAX_PKCS11_CERT_CHA</span></span>
<span id="LC4" class="line" lang="console"><span class="gp">cert-cred-x509.c:       pcerts = gnutls_malloc(sizeof(gnutls_pcert_st) * count);</span></span>
<span id="LC5" class="line" lang="console"><span class="go">cert-cred-x509.c:       ccert = gnutls_malloc(sizeof(*ccert)*MAX_PKCS11_CERT_CHA</span></span>
<span id="LC6" class="line" lang="console"><span class="gp">IN);</span></span>
<span id="LC7" class="line" lang="console"><span class="gp">cert-cred-x509.c:       pcerts = gnutls_malloc(sizeof(gnutls_pcert_st) * cert_list_size);</span></span>
<span id="LC8" class="line" lang="console"><span class="gp">cert-cred-x509.c:       new_list = gnutls_malloc(ca_list_size * sizeof(gnutls_x509_crt_t));</span></span>
<span id="LC9" class="line" lang="console"><span class="gp">cert-cred-x509.c:       gnutls_x509_crl_t *new_crl = gnutls_malloc(crl_list_size * sizeof(gnutls_x509_crl_t));</span></span>
<span id="LC10" class="line" lang="console"><span class="gp">cert-cred.c:    new_pcert_list = gnutls_malloc(sizeof(gnutls_pcert_st) * pcert_list_size);</span></span>
<span id="LC11" class="line" lang="console"><span class="gp">cert-cred.c:    local_certs = gnutls_malloc(sizeof(gnutls_pcert_st) * ncerts);</span></span>
<span id="LC12" class="line" lang="console"><span class="gp">pcert.c:        crt = gnutls_malloc((*pcert_list_size) * sizeof(gnutls_x509_crt_t));</span></span>
<span id="LC13" class="line" lang="console"><span class="gp">pkcs11.c:           gnutls_malloc(sizeof(gnutls_buffer_st) * list-></span>key_ids_size<span class="o">)</span><span class="p">;</span></span>
<span id="LC14" class="line" lang="console"><span class="gp">pkcs11.c:       ctx = gnutls_malloc(OBJECTS_A_TIME*sizeof(ctx[0]));</span></span>
<span id="LC15" class="line" lang="console"><span class="gp">x509/crl.c:     *crls = gnutls_malloc(sizeof(gnutls_x509_crl_t) * init);</span></span>
<span id="LC16" class="line" lang="console"><span class="gp">x509/ocsp.c:            *ocsps = gnutls_malloc(1*sizeof(gnutls_ocsp_resp_t));</span></span>
<span id="LC17" class="line" lang="console"><span class="gp">x509/verify-high2.c:    xcrt_list = gnutls_malloc(sizeof(gnutls_x509_crt_t) * pcrt_list_size);</span></span>
<span id="LC18" class="line" lang="console"><span class="gp">x509/verify-high2.c:    xcrt_list = gnutls_malloc(sizeof(gnutls_x509_crt_t) * pcrt_list_size);</span></span>
<span id="LC19" class="line" lang="console"><span class="gp">x509/x509.c:    *certs = gnutls_malloc(sizeof(gnutls_x509_crt_t) * init);</span></span>
<span id="LC20" class="line" lang="console"><span class="gp">x509/x509.c:    *certs = gnutls_malloc(total*sizeof(gnutls_x509_crt_t));</span></span></code></pre>
<p dir="auto">I assume most of them are for internal use, but it would be nice to replace them with <code>gnutls_calloc</code> unless there is any good reason to do the check by ourselves.</p>

</div>
<div class="footer" style="margin-top: 10px;">
<p style="font-size: small; color: #666;">

<br>
Reply to this email directly or <a href="https://gitlab.com/gnutls/gnutls/-/issues/1179">view it on GitLab</a>.
<br>
You're receiving this email because of your account on gitlab.com.
If you'd like to receive fewer emails, you can
<a href="https://gitlab.com/-/sent_notifications/d07f47b2aa21e39892ecd118a6e79433/unsubscribe">unsubscribe</a>
from this thread or
adjust your notification settings.
<script type="application/ld+json">{"@context":"http://schema.org","@type":"EmailMessage","action":{"@type":"ViewAction","name":"View Issue","url":"https://gitlab.com/gnutls/gnutls/-/issues/1179"}}</script>


</p>
</div>
</body>
</html>