[Pkg-wmaker-commits] [wmbiff] 01/07: strcpy is not defined to handle overlapping regions. valgrind complains, rightly, so reimplement lefttrim to avoid such behavior

Doug Torrance dtorrance-guest at moszumanska.debian.org
Thu Aug 20 03:04:40 UTC 2015


This is an automated email from the git hooks/post-receive script.

dtorrance-guest pushed a commit to tag wmbiff_0_4_19
in repository wmbiff.

commit bfe383e9194b30646974a8c2e70e6056d851d177
Author: bluehal <bluehal>
Date:   Sat Nov 8 22:58:54 2003 +0000

    strcpy is not defined to handle overlapping regions.  valgrind complains, rightly, so reimplement lefttrim to avoid such behavior
---
 wmbiff/ShellClient.c |  8 ++++++--
 wmbiff/charutil.c    | 11 +++++++++--
 2 files changed, 15 insertions(+), 4 deletions(-)

diff --git a/wmbiff/ShellClient.c b/wmbiff/ShellClient.c
index c1328da..7288733 100644
--- a/wmbiff/ShellClient.c
+++ b/wmbiff/ShellClient.c
@@ -283,9 +283,13 @@ int shellCreate( /*@notnull@ */ Pop3 pc, const char *str)
 	}
 	commandline++;				/* shell:::> */
 
-	/* good thing strcpy handles overlapping regions */
+	/* strcpy is not specified to handle overlapping regions */
 	SH_DM(pc, DEBUG_INFO, "path= '%s'\n", commandline);
-	strcpy(pc->path, commandline);
+	{
+		char *tmp = strdup(commandline);
+		strcpy(pc->path, tmp);
+		free(tmp);
+	}
 	return 0;
 }
 
diff --git a/wmbiff/charutil.c b/wmbiff/charutil.c
index f8b98e5..12c5fa7 100644
--- a/wmbiff/charutil.c
+++ b/wmbiff/charutil.c
@@ -1,4 +1,4 @@
-/* $Id: charutil.c,v 1.15 2003/01/19 13:13:04 bluehal Exp $ */
+/* $Id: charutil.c,v 1.16 2003/11/08 22:58:54 bluehal Exp $ */
 #ifdef HAVE_CONFIG_H
 #include <config.h>
 #endif
@@ -21,7 +21,14 @@ static __inline__ void LeftTrim(char *psValue)
 	while (*psTmp == ' ' || *psTmp == '\t')
 		psTmp++;
 
-	strcpy(psValue, psTmp);
+	/* can't use strcpy here, as the strings must not
+	   overlap, at least according to spec. */
+	if (psTmp > psValue) {
+		while (*psTmp != '\0') {
+			*(psValue++) = *(psTmp++);
+		}
+		*(psValue) = '\0';
+	}
 }
 
 static __inline__ void RightTrim(char *psValue)

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-wmaker/wmbiff.git



More information about the Pkg-wmaker-commits mailing list