<!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/davidtr1037">David Trabish</a> created an issue <a href="https://gitlab.com/gnutls/libtasn1/-/issues/32">#32</a>:
</p>
<div></div>
<h2 dir="auto">
<a id="user-content-description-of-problem" class="anchor" href="#description-of-problem" aria-hidden="true"></a>Description of problem:</h2>
<p dir="auto">The bound check in ETYPE_OK may lead to out-of-bound access.</p>
<h2 dir="auto">
<a id="user-content-version-of-libtasn1-used" class="anchor" href="#version-of-libtasn1-used" aria-hidden="true"></a>Version of libtasn1 used:</h2>
<p dir="auto">4.16.0</p>
<h2 dir="auto">
<a id="user-content-distributor-of-libtasn1-eg-ubuntu-fedora-rhel" class="anchor" href="#distributor-of-libtasn1-eg-ubuntu-fedora-rhel" aria-hidden="true"></a>Distributor of libtasn1 (e.g., Ubuntu, Fedora, RHEL)</h2>
<p dir="auto">Ubuntu</p>
<h2 dir="auto">
<a id="user-content-how-reproducible" class="anchor" href="#how-reproducible" aria-hidden="true"></a>How reproducible:</h2>
<pre class="code highlight js-syntax-highlight plaintext" lang="plaintext" v-pre="true"><code><span id="LC1" class="line" lang="plaintext">#include <stdlib.h></span>
<span id="LC2" class="line" lang="plaintext">#include <stdio.h></span>
<span id="LC3" class="line" lang="plaintext">#include <libtasn1.h></span>
<span id="LC4" class="line" lang="plaintext"></span>
<span id="LC5" class="line" lang="plaintext">int main(int argc, char *argv[]) {</span>
<span id="LC6" class="line" lang="plaintext">    unsigned int etype = 38;</span>
<span id="LC7" class="line" lang="plaintext"></span>
<span id="LC8" class="line" lang="plaintext">    unsigned int str_len = 10;</span>
<span id="LC9" class="line" lang="plaintext">    unsigned char *str = malloc(str_len);</span>
<span id="LC10" class="line" lang="plaintext"></span>
<span id="LC11" class="line" lang="plaintext">    unsigned int tl_len = 10;</span>
<span id="LC12" class="line" lang="plaintext">    unsigned char *tl = malloc(tl_len);</span>
<span id="LC13" class="line" lang="plaintext"></span>
<span id="LC14" class="line" lang="plaintext">    asn1_encode_simple_der(etype, str, str_len, tl, &tl_len);</span>
<span id="LC15" class="line" lang="plaintext">    </span>
<span id="LC16" class="line" lang="plaintext">    return 0;</span>
<span id="LC17" class="line" lang="plaintext">}</span></code></pre>
<p dir="auto">Steps to Reproduce:</p>
<ul dir="auto">
<li>Compile the program with <code>-fsanitize=address,leak,undefined</code>
</li>
<li>Run</li>
</ul>
<h2 dir="auto">
<a id="user-content-actual-results" class="anchor" href="#actual-results" aria-hidden="true"></a>Actual results:</h2>
<pre class="code highlight js-syntax-highlight plaintext" lang="plaintext" v-pre="true"><code><span id="LC1" class="line" lang="plaintext">==23616==ERROR: AddressSanitizer: global-buffer-overflow on address 0x00000042e208 at pc 0x000000402854 bp 0x7fffe0995170 sp 0x7fffe0995160</span>
<span id="LC2" class="line" lang="plaintext">READ of size 8 at 0x00000042e208 thread T0</span>
<span id="LC3" class="line" lang="plaintext">    #0 0x402853 in asn1_encode_simple_der ../../libtasn1-4.16.0/lib/coding.c:218</span></code></pre>
<h2 dir="auto">
<a id="user-content-expected-results" class="anchor" href="#expected-results" aria-hidden="true"></a>Expected results:</h2>
<p dir="auto">The macro should do this check instead:</p>
<pre class="code highlight js-syntax-highlight plaintext" lang="plaintext" v-pre="true"><code><span id="LC1" class="line" lang="plaintext">(etype) < _asn1_tags_size</span></code></pre>

</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/libtasn1/-/issues/32">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/081d195a97ae09f44fd8ecb25321ecd5/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/libtasn1/-/issues/32"}}</script>


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