[lfs-patches] r2957 - trunk/nfs-utils

cjg at higgs.linuxfromscratch.org cjg at higgs.linuxfromscratch.org
Sun Jul 27 04:18:13 PDT 2014


Author: cjg
Date: Sun Jul 27 04:18:13 2014
New Revision: 2957

Log:
Just added a patch for nfs-utils that fixes run-time segfaults when using gcc 4.9.x.

Added:
   trunk/nfs-utils/nfs-utils-1.3.0-gcc-4.9-1.patch

Added: trunk/nfs-utils/nfs-utils-1.3.0-gcc-4.9-1.patch
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ trunk/nfs-utils/nfs-utils-1.3.0-gcc-4.9-1.patch	Sun Jul 27 04:18:13 2014	(r2957)
@@ -0,0 +1,70 @@
+Submitted By: Christopher Gregory <cjg at linuxfromscratch dot org>
+Date: 2010-09-03
+Initial Package Version: 1.3.0
+Upstream Status: unknown
+Origin:  found on gentoo portage message board.
+Description: Fix add_name segfault with gcc 4.9.x
+Comment:
+
+From 25e83c2270b2d2966c992885faed0b79be09f474 Mon Sep 17 00:00:00 2001
+From: Jeff Layton <jlayton at poochiereds.net>
+Date: Thu, 1 May 2014 11:15:16 -0400
+Subject: [PATCH [nfs-utils]] mountd: fix segfault in add_name with newer gcc
+ compilers
+
+I hit a segfault in add_name with a mountd built with gcc-4.9.0. Some
+NULL pointer checks got reordered such that a pointer was dereferenced
+before checking to see whether it was NULL. The problem was due to
+nfs-utils relying on undefined behavior, which tricked gcc into assuming
+that the pointer would never be NULL.
+
+At first I assumed that this was a compiler bug, but Jakub Jelinek and
+Jeff Law pointed out:
+
+"If old is NULL, then:
+
+	strncpy(new, old, cp-old);
+
+is undefined behavior (even when cp == old == NULL in that case),
+therefore gcc assumes that old is never NULL, as otherwise it would be
+invalid.
+
+Just guard
+	strncpy(new, old, cp-old);
+	new[cp-old] = 0;
+with if (old) { ... }."
+
+This patch does that. If old is NULL though, then we still need to
+ensure that new is NULL terminated, lest the subsequent strcats walk off
+the end of it.
+
+Cc: Jeff Law <law at redhat.com>
+Cc: Jakub Jelinek <jakub at redhat.com>
+Signed-off-by: Jeff Layton <jlayton at poochiereds.net>
+Signed-off-by: Steve Dickson <steved at redhat.com>
+---
+ support/export/client.c | 8 ++++++--
+ 1 file changed, 6 insertions(+), 2 deletions(-)
+
+diff --git a/support/export/client.c b/support/export/client.c
+index dbf47b9..f85e11c 100644
+--- a/support/export/client.c
++++ b/support/export/client.c
+@@ -482,8 +482,12 @@ add_name(char *old, const char *add)
+ 		else
+ 			cp = cp + strlen(cp);
+ 	}
+-	strncpy(new, old, cp-old);
+-	new[cp-old] = 0;
++	if (old) {
++		strncpy(new, old, cp-old);
++		new[cp-old] = 0;
++	} else {
++		new[0] = 0;
++	}
+ 	if (cp != old && !*cp)
+ 		strcat(new, ",");
+ 	strcat(new, add);
+-- 
+2.0.0
+


More information about the patches mailing list