LD_PRELOAD causes stack smashing error in gpg

devnoname120 via Gnupg-devel <[email protected]> Sat, 18 Apr 2026 18:53:39 +0200
Newsgroups gmane.comp.encryption.gpg.devel
Message-ID <21fdd26a-bb6f-4454-a110-b95c975681c9@Spark>
--===============1230736608341580673==
Content-Type: multipart/alternative; boundary="69e3b722_507ed7ab_153a1"

--69e3b722_507ed7ab_153a1
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline

=46or some reason gpg doesn=E2=80=99t seem to like when a RegEx is compil=
ed in the constructor of a preloaded library. I haven=E2=80=99t seen this=
 happen in other software, any ideas what could be causing this=3F

Minimum repo:

=46ile =60/tmp/repo.c=60:

=60=60=60c
=23define =5FGNU=5FSOURCE
=23include <regex.h>

=5F=5Fattribute=5F=5F((constructor)) static void init(void) =7B
=C2=A0regex=5Ft regex;
=C2=A0regcomp(&regex, =22=22, 0);
=7D
=60=60=60

Shell:

=60=60=60sh
gcc -shared -fPIC -o /tmp/repro.so /tmp/repro.c
export LD=5FPRELOAD=3D/tmp/repro.so
gpg --list-keys
=60=60=60

Output:

=60=60=60
*** stack smashing detected ***: terminated
Aborted
=60=60=60

--69e3b722_507ed7ab_153a1
Content-Type: text/html; charset="utf-8"
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline

<html xmlns=3D=22http://www.w3.org/1999/xhtml=22>
<head>
<title></title>
</head>
<body>
<div name=3D=22messageBodySection=22>
<div>=46or some reason gpg doesn=E2=80=99t seem to like when a RegEx is c=
ompiled in the constructor of a preloaded library. I haven=E2=80=99t seen=
 this happen in other software, any ideas what could be causing this=3F</=
div>
<div>&=23160;</div>
<div>Minimum repo:</div>
<div>&=23160;</div>
<div>=46ile =60/tmp/repo.c=60:</div>
<div>&=23160;</div>
<div>=60=60=60c<br />
=23define =5FGNU=5FSOURCE<br />
=23include &lt;regex.h&gt;</div>
<div>&=23160;</div>
<div>=5F=5Fattribute=5F=5F((constructor)) static void init(void) =7B<br /=
>
&=23160;regex=5Ft regex;<br />
&=23160;regcomp(&amp;regex, =22=22, 0);<br />
=7D<br />
=60=60=60</div>
<div>&=23160;</div>
<div>Shell:</div>
<div>&=23160;</div>
<div>=60=60=60sh<br />
gcc -shared -fPIC -o /tmp/<a href=3D=22repro.so=22>repro.so</a> /tmp/repr=
o.c<br />
export LD=5FPRELOAD=3D/tmp/<a href=3D=22repro.so=22>repro.so</a><br />
gpg --list-keys<br />
=60=60=60</div>
<div>&=23160;</div>
<div>Output:</div>
<div>&=23160;</div>
<div>=60=60=60<br />
*** stack smashing detected ***: terminated<br />
Aborted<br />
=60=60=60</div>
</div>
</body>
</html>

--69e3b722_507ed7ab_153a1--



--===============1230736608341580673==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

_______________________________________________
Gnupg-devel mailing list
[email protected]
https://lists.gnupg.org/mailman/listinfo/gnupg-devel

--===============1230736608341580673==--