public inbox for linux-xfs@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] xfsrestore: fix string corruption in shrink()
@ 2014-11-13 19:14 Mark Tinguely
  2014-11-13 19:41 ` Eric Sandeen
  0 siblings, 1 reply; 6+ messages in thread
From: Mark Tinguely @ 2014-11-13 19:14 UTC (permalink / raw)
  To: xfs

[-- Attachment #1: xfsrestore-fix-string-corruption-in-shrink.patch --]
[-- Type: text/plain, Size: 1402 bytes --]

Linux strcpy() corrupts the output string when the input
and output strings overlap. The shrink() function in xfsrestore
uses an overlapping strcpy() to remove special characters when
processing an interactive command line. The resultant command
will fail.

examples:
 -> cd "AOGC exome chip core genotyping"
AOGC exome chp  core genotyping not found
 -> cd "t t"
tt not found

Fix my manually moving the characters in the array.

Signed-off-by: Mark Tinguely <tinguely@sgi.com>
---
 restore/tree.c |   14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)

Index: b/restore/tree.c
===================================================================
--- a/restore/tree.c
+++ b/restore/tree.c
@@ -4857,7 +4857,19 @@ distance_to_space( char *s, char *l )
 static void
 shrink( char *s, size_t cnt )
 {
-	strcpy( s, s + cnt );
+	/*
+	 * Linux strcpy corrupts the string if the src and dst overlap.
+	 * Manually copy the entries to the left.
+	 *
+	 * Since the liter array is mostly nulls, shrink is not moving
+	 * the array left as intended. Does not seem to be many embedded
+	 * processing characters, so leaving it for now
+	 */
+	char *m = s + cnt;
+	while (*m != '\0')
+		*s++ = *m++;
+	/* NULL the last character of the string */
+	*s = '\0';
 }
 
 static int


_______________________________________________
xfs mailing list
xfs@oss.sgi.com
http://oss.sgi.com/mailman/listinfo/xfs

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2014-11-13 21:57 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-11-13 19:14 [PATCH] xfsrestore: fix string corruption in shrink() Mark Tinguely
2014-11-13 19:41 ` Eric Sandeen
2014-11-13 19:56   ` Mark Tinguely
2014-11-13 20:45     ` Eric Sandeen
2014-11-13 21:57       ` Mark Tinguely
2014-11-13 21:50     ` Dave Chinner

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox