1 From 8b03fdbfb0dd8e0147aa61ff30b8311235caf5f3 Mon Sep 17 00:00:00 2001
2 From: Jeff Layton <jlayton@poochiereds.net>
3 Date: Thu, 1 May 2014 11:15:16 -0400
4 Subject: [PATCH] mountd: fix segfault in add_name with newer gcc compilers
5 Bug-Debian: http://bugs.debian.org/757835
6 Bug-Ubuntu: https://bugs.launchpad.net/ubuntu/+bug/1355829
8 I hit a segfault in add_name with a mountd built with gcc-4.9.0. Some
9 NULL pointer checks got reordered such that a pointer was dereferenced
10 before checking to see whether it was NULL. The problem was due to
11 nfs-utils relying on undefined behavior, which tricked gcc into assuming
12 that the pointer would never be NULL.
14 At first I assumed that this was a compiler bug, but Jakub Jelinek and
17 "If old is NULL, then:
19 strncpy(new, old, cp-old);
21 is undefined behavior (even when cp == old == NULL in that case),
22 therefore gcc assumes that old is never NULL, as otherwise it would be
26 strncpy(new, old, cp-old);
28 with if (old) { ... }."
30 This patch does that. If old is NULL though, then we still need to
31 ensure that new is NULL terminated, lest the subsequent strcats walk off
34 Cc: Jeff Law <law@redhat.com>
35 Cc: Jakub Jelinek <jakub@redhat.com>
36 Signed-off-by: Jeff Layton <jlayton@poochiereds.net>
37 Signed-off-by: Steve Dickson <steved@redhat.com>
39 support/export/client.c | 8 ++++++--
40 1 file changed, 6 insertions(+), 2 deletions(-)
42 diff --git a/support/export/client.c b/support/export/client.c
43 index ba2db8f..e749cac 100644
44 --- a/support/export/client.c
45 +++ b/support/export/client.c
46 @@ -482,8 +482,12 @@ add_name(char *old, const char *add)
50 - strncpy(new, old, cp-old);
53 + strncpy(new, old, cp-old);
58 if (cp != old && !*cp)