Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 28 Jan 2012 18:49:04 +0000 (UTC)
From:      Tijl Coosemans <tijl@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r230649 - head/usr.bin/hexdump
Message-ID:  <201201281849.q0SIn4qv095108@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: tijl
Date: Sat Jan 28 18:49:04 2012
New Revision: 230649
URL: http://svn.freebsd.org/changeset/base/230649

Log:
  Fix decoding of escape sequences in format strings:
  - Zero-terminate the resulting string by letting the for-loop copy the
    terminating zero.
  - Exit the for-loop after handling a backslash at the end of the format
    string to fix a buffer overrun.
  - Remove some unnecessary comments and blank lines. [1]
  
  Requested by:	bde [1]
  PR:		bin/144722
  Approved by:	kib (mentor)

Modified:
  head/usr.bin/hexdump/parse.c

Modified: head/usr.bin/hexdump/parse.c
==============================================================================
--- head/usr.bin/hexdump/parse.c	Sat Jan 28 18:35:10 2012	(r230648)
+++ head/usr.bin/hexdump/parse.c	Sat Jan 28 18:49:04 2012	(r230649)
@@ -451,21 +451,14 @@ escape(char *p1)
 	char *p2;
 
 	/* alphabetic escape sequences have to be done in place */
-	for (p2 = p1; *p1; p1++, p2++) {
-		/* 
-		 * Let's take a peak at the next item and see whether or not
-		 * we need to escape the value...
-		 */
+	for (p2 = p1;; p1++, p2++) {
 		if (*p1 == '\\') {
-
 			p1++;
-
 			switch(*p1) {
-			/* A standalone `\' */
 			case '\0':
 				*p2 = '\\';
 				*++p2 = '\0';
-				break;
+				return;
 			case 'a':
 			     /* *p2 = '\a'; */
 				*p2 = '\007';
@@ -492,12 +485,12 @@ escape(char *p1)
 				*p2 = *p1;
 				break;
 			}
-
-		} else
+		} else {
 			*p2 = *p1;
-
+			if (*p1 == '\0')
+				return;
+		}
 	}
-
 }
 
 void



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201201281849.q0SIn4qv095108>