Page MenuHome GnuPG

gnupg: regexp and build with -fsanitize=address
Open, NormalPublic

Description

Reading the report by @collinfunk , I also tried a build with -fsanitize=address (adding CFLAGS='-O3 -g -fno-omit-frame-pointer -fsanitize=address' to configure options (for libgpg-error, libgcrypt, and gnupg).

I have the failure result of gnupg for tests/openpgp/trust-pgp-4.scm.

I located the issue, it is because of regexp routines in libasan library.

$ ./bin/gpg --import ../../wg/gnupg/tests/openpgp/trust-pgp/scenario4.asc
$ ./bin/gpg --debug=trust --check-trustdb --yes
[...]
gpg: DBG: regexp '<[^>]+[@.]example\\.com>$' ('<[^>]+[@.]example\\.com>$') on 'Heidi <heidi@example.org>': NO

... which should be:

gpg: DBG: regexp '<[^>]+[@.]example\\.org>$' ('<[^>]+[@.]example\\.org>$') on 'Heidi <heidi@example.org>': YES
gpg: DBG: trust sig on Heidi <heidi@example.org>, sig depth is 2, kr depth is 1

Event Timeline

gniibe triaged this task as Normal priority.Wed, May 28, 9:06 AM
gniibe created this task.

The issue is the routines of regcomp, regexec, regerror and regfree are in C library and the sanitizer library replaces them (and it's not compatible for the use case of GnuPG).

For normal build, the routines in gnupg/regexp/ are chosen correctly as expected, but with the sanitizer, the one of libasan are chosen.

It is safe to have different names for those routines.
Here is a patch I'm trying.

diff --git a/g10/Makefile.am b/g10/Makefile.am
index 4e1306da3..717d64a33 100644
--- a/g10/Makefile.am
+++ b/g10/Makefile.am
@@ -26,7 +26,7 @@ EXTRA_DIST = distsigkey.gpg \
 	     t-keydb-get-keyblock.gpg t-stutter-data.asc \
 	     all-tests.scm
 
-AM_CPPFLAGS =
+AM_CPPFLAGS = -DREGEXP_PREFIX=gnupg_
 
 include $(top_srcdir)/am/cmacros.am
 
diff --git a/regexp/Makefile.am b/regexp/Makefile.am
index 307aacf9d..4da8687ce 100644
--- a/regexp/Makefile.am
+++ b/regexp/Makefile.am
@@ -20,7 +20,7 @@
 
 noinst_LIBRARIES = libregexp.a
 
-AM_CPPFLAGS = -DJIM_REGEXP -DJIM_UTF8 -DUSE_UTF8
+AM_CPPFLAGS = -DJIM_REGEXP -DJIM_UTF8 -DUSE_UTF8 -DREGEXP_PREFIX=gnupg_
 
 AM_CFLAGS =
 
diff --git a/regexp/jimregexp.h b/regexp/jimregexp.h
index ab734797b..28aa6d686 100644
--- a/regexp/jimregexp.h
+++ b/regexp/jimregexp.h
@@ -1,6 +1,14 @@
 #ifndef JIMREGEXP_H
 #define JIMREGEXP_H
 
+#ifdef REGEXP_PREFIX
+#define ADD_PREFIX(name) REGEXP_PREFIX ## name
+#define regcomp ADD_PREFIX(regcomp)
+#define regexec ADD_PREFIX(regexec)
+#define regerror ADD_PREFIX(regerror)
+#define regfree ADD_PREFIX(regfree)
+#endif
+
 /** regexp(3)-compatible regular expression implementation for Jim.
  *
  * See jimregexp.c for details
gniibe updated the task description. (Show Details)
gniibe updated the task description. (Show Details)
gniibe renamed this task from gnupg: regexp and build with -fsanitize=addres to gnupg: regexp and build with -fsanitize=address.Wed, May 28, 9:15 AM
gniibe updated the task description. (Show Details)

Please remember to add a comment to the code describing the reason for this renaming.

@gniibe Thanks! I noticed this too but wasn't familiar with the test suite, and didn't see an ASAN error so assumed nothing harmful. This explanation explains it.