<!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: #777;">
<a href="https://gitlab.com/gstrauss">Glenn Strauss</a> created an issue <a href="https://gitlab.com/gnutls/gnutls/-/issues/1006">#1006</a>:
</p>
<div></div>
<p dir="auto">lib/file.c <code>gnutls_load_file()</code> does not include trailing <code>'\0'</code> if <code>malloc != gnutls_malloc</code> and does not check if <code>gnutls_malloc()</code> fails.</p>
<pre class="code highlight js-syntax-highlight plaintext" lang="plaintext" v-pre="true"><code><span id="LC1" class="line" lang="plaintext">--- a/lib/file.c</span>
<span id="LC2" class="line" lang="plaintext">+++ b/lib/file.c</span>
<span id="LC3" class="line" lang="plaintext">@@ -60,11 +60,14 @@ int gnutls_load_file(const char *filename, gnutls_datum_t * data)</span>
<span id="LC4" class="line" lang="plaintext">                return GNUTLS_E_FILE_ERROR;</span>
<span id="LC5" class="line" lang="plaintext"> </span>
<span id="LC6" class="line" lang="plaintext">        if (malloc != gnutls_malloc) {</span>
<span id="LC7" class="line" lang="plaintext">-               void *tmp = gnutls_malloc(len);</span>
<span id="LC8" class="line" lang="plaintext">-</span>
<span id="LC9" class="line" lang="plaintext">-               memcpy(tmp, data->data, len);</span>
<span id="LC10" class="line" lang="plaintext">+               void *tmp = gnutls_malloc(len+1);</span>
<span id="LC11" class="line" lang="plaintext">+               if (tmp)</span>
<span id="LC12" class="line" lang="plaintext">+                       memcpy(tmp, data->data, len+1);</span>
<span id="LC13" class="line" lang="plaintext">+               zeroize_key(data->data, len);</span>
<span id="LC14" class="line" lang="plaintext">                free(data->data);</span>
<span id="LC15" class="line" lang="plaintext">                data->data = tmp;</span>
<span id="LC16" class="line" lang="plaintext">+               if (tmp == NULL)</span>
<span id="LC17" class="line" lang="plaintext">+                       return GNUTLS_E_FILE_ERROR;</span>
<span id="LC18" class="line" lang="plaintext">        }</span>
<span id="LC19" class="line" lang="plaintext"> </span>
<span id="LC20" class="line" lang="plaintext">        data->size = len;</span></code></pre>
<p dir="auto">Note: <code>gnutls_load_file()</code> also does not check that (size_t) len < UINT_MAX before assigning len in <code>data->size = len;</code> (fix not included above)</p>

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

<br>
Reply to this email directly or <a href="https://gitlab.com/gnutls/gnutls/-/issues/1006">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/5a02c937af391b5e36f3c1243e276218/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/1006"}}</script>


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