<!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 style="color: #777777;">
<a href="https://gitlab.com/tobhe">Tobias Heider</a>
<a href="https://gitlab.com/gnutls/gnutls/-/merge_requests/1554#note_879633463">commented</a>:
</p>
<div class="md" style="">
<p dir="auto"><a href="https://gitlab.com/dueno" data-user="470892" data-reference-type="user" data-container="body" data-placement="top" class="gfm gfm-project_member js-user-link" title="Daiki Ueno">@dueno</a> conflicting overrides indeed seem to be a problem...</p>
<p dir="auto">In the guile case i think the following hack could solve the problem:</p>
<div class="gl-relative markdown-code-block js-markdown-code">
<pre class="code highlight js-syntax-highlight language-plaintext" lang="plaintext" v-pre="true" style="border-radius: 2px; margin: 0 0 8px; padding: 8px 12px; border: 1px solid #dbdbdb;"><code><span id="LC1" class="line" lang="plaintext">void (*reallocfunc) (void *, size_t);</span>
<span id="LC2" class="line" lang="plaintext">void (*freefunc) (void *, size_t);</span>
<span id="LC3" class="line" lang="plaintext">void (*defreallocfunc) (void *, size_t);</span>
<span id="LC4" class="line" lang="plaintext">void (*deffreefunc) (void *, size_t);</span>
<span id="LC5" class="line" lang="plaintext"></span>
<span id="LC6" class="line" lang="plaintext">/* Get previous allocators */</span>
<span id="LC7" class="line" lang="plaintext">mp_get_memory_functions(NULL, &reallocfunc, &freefunc);</span>
<span id="LC8" class="line" lang="plaintext"></span>
<span id="LC9" class="line" lang="plaintext">/* Reset to defaults */</span>
<span id="LC10" class="line" lang="plaintext">mp_set_memory_functions(NULL, NULL, NULL);</span>
<span id="LC11" class="line" lang="plaintext"></span>
<span id="LC12" class="line" lang="plaintext">/* Get default allocators */</span>
<span id="LC13" class="line" lang="plaintext">mp_get_memory_functions(NULL, &defreallocfunc, &deffreefunc);</span>
<span id="LC14" class="line" lang="plaintext"></span>
<span id="LC15" class="line" lang="plaintext">/* See if free or realloc have been overriden before */</span>
<span id="LC16" class="line" lang="plaintext">if (reallocfunc != defreallocfunc || freefunc != deffreefunc)</span>
<span id="LC17" class="line" lang="plaintext">    goto donothing;</span>
<span id="LC18" class="line" lang="plaintext"></span>
<span id="LC19" class="line" lang="plaintext">/* Overload GMP allocators with safe alternatives */</span>
<span id="LC20" class="line" lang="plaintext">mp_set_memory_functions(NULL, gnutls_realloc_zero, gnutls_free_zero);</span></code></pre>
<copy-code></copy-code>
</div>
<p dir="auto">This probably isn't the most elegant solution but reading the gmp code and documentation i think it should do the job.</p>
<p dir="auto">What i am really more worried about is applications overriding the allocators when you actually want FIPS compliance and secure deletion.
The best solution in the long term would probably be sth like a <code>gmp_ctx</code> which can be passed to every gmp function call instead of a single global setting. The <code>gmp_ctx</code> then stores the pointers to the allocator functions so that every caller can pass their own allocators.</p>
<p dir="auto">I can't really think of an easy fix other than just saying: don't override gmp allocators if want things to be securely deleted for you, otherwise you are on yourself.</p>
</div>


</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/-/merge_requests/1554#note_879633463">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/b9790ee4796a55471e23311f00deb67c/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 Merge request","url":"https://gitlab.com/gnutls/gnutls/-/merge_requests/1554#note_879633463"}}</script>


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