From af4cd47b9f259ddc005a1186dc7f1337af4f4dab Mon Sep 17 00:00:00 2001 From: Tomas Korbar Date: Mon, 6 Apr 2020 08:59:18 +0200 Subject: [PATCH] Fix undefined behaviour on build with -D_FORTIFY_SOURCE=2 Found by tstellar@redhat.com --- memcached-1.6.3-dfortify.patch | 51 ++++++++++++++++++++++++++++++++++ memcached.spec | 8 +++++- 2 files changed, 58 insertions(+), 1 deletion(-) create mode 100644 memcached-1.6.3-dfortify.patch diff --git a/memcached-1.6.3-dfortify.patch b/memcached-1.6.3-dfortify.patch new file mode 100644 index 0000000..9e426f2 --- /dev/null +++ b/memcached-1.6.3-dfortify.patch @@ -0,0 +1,51 @@ +From c65973d08c4dffbb38ce032d00b901d0ce534c6f Mon Sep 17 00:00:00 2001 +From: Tom Stellard +Date: Mon, 30 Mar 2020 17:49:38 +0000 +Subject: [PATCH] Fix undefined behavior when compiling with + -D_FORTIFY_SOURCE=2 + +When compiling with -D_FORTIFY_SOURCE=2, printf is defined as a macro, +which makes the #ifdef TLS block in the usage() function of memcached.c +undefined behavior. + +This warning was caught by compiling with clang: + +memcached.c:7829:2: error: embedding a directive within macro arguments has undefined behavior [-Werror,-Wembedded-directive] + ^ +memcached.c:7832:2: error: embedding a directive within macro arguments has undefined behavior [-Werror,-Wembedded-directive] + ^ +--- + memcached.c | 11 ++++++----- + 1 file changed, 6 insertions(+), 5 deletions(-) + +diff --git a/memcached.c b/memcached.c +index 2592b3f94..148a3b55a 100644 +--- a/memcached.c ++++ b/memcached.c +@@ -7825,12 +7825,13 @@ static void usage(void) { + "-s, --unix-socket= UNIX socket to listen on (disables network support)\n" + "-A, --enable-shutdown enable ascii \"shutdown\" command\n" + "-a, --unix-mask= access mask for UNIX socket, in octal (default: %o)\n" +- "-l, --listen= interface to listen on (default: INADDR_ANY)\n" ++ "-l, --listen= interface to listen on (default: INADDR_ANY)\n", ++ settings.port, settings.udpport, settings.access); + #ifdef TLS +- " if TLS/SSL is enabled, 'notls' prefix can be used to\n" +- " disable for specific listeners (-l notls::) \n" ++ printf(" if TLS/SSL is enabled, 'notls' prefix can be used to\n" ++ " disable for specific listeners (-l notls::) \n"); + #endif +- "-d, --daemon run as a daemon\n" ++ printf("-d, --daemon run as a daemon\n" + "-r, --enable-coredumps maximize core file limit\n" + "-u, --user= assume identity of (only when run as root)\n" + "-m, --memory-limit= item memory in megabytes (default: %lu)\n" +@@ -7846,7 +7847,7 @@ static void usage(void) { + "-P, --pidfile= save PID in , only used with -d option\n" + "-f, --slab-growth-factor= chunk size growth factor (default: %2.2f)\n" + "-n, --slab-min-size= min space used for key+value+flags (default: %d)\n", +- settings.port, settings.udpport, settings.access, (unsigned long) settings.maxbytes / (1 << 20), ++ (unsigned long) settings.maxbytes / (1 << 20), + settings.maxconns, settings.factor, settings.chunk_size); + verify_default("udp-port",settings.udpport == 0); + printf("-L, --enable-largepages try to use large memory pages (if available)\n"); diff --git a/memcached.spec b/memcached.spec index 5f36abe..974948a 100644 --- a/memcached.spec +++ b/memcached.spec @@ -12,7 +12,7 @@ Name: memcached Version: 1.6.3 -Release: 1%{?dist} +Release: 2%{?dist} Epoch: 0 Summary: High Performance, Distributed Memory Object Cache @@ -24,6 +24,7 @@ Source1: memcached.sysconfig Source2: https://releases.pagure.org/memcached-selinux/memcached-selinux-1.0.2.tar.gz Patch1: memcached-unit.patch +Patch2: memcached-1.6.3-dfortify.patch BuildRequires: gcc libevent-devel systemd BuildRequires: perl-generators @@ -68,6 +69,7 @@ optimised for use with this version of memcached. # and SELinux policy sources into memcached-selinux-X.X %setup -q -b 2 %patch1 -p1 -b .unit +%patch2 -p1 -b .dfortify %build %configure \ @@ -173,6 +175,10 @@ fi %license ../%{selinuxmoduledir}/COPYING %changelog +* Mon Apr 06 2020 Tomas Korbar - 0:1.6.3-2 +- Fix undefined behaviour on build with -D_FORTIFY_SOURCE=2 +- Found by tstellar@redhat.com + * Sun Mar 29 2020 Tomas Korbar - 0:1.6.3-1 - Update to 1.6.3