Author: tijl
Date: Mon Feb 13 10:24:49 2012
New Revision: 231578
URL: http://svn.freebsd.org/changeset/base/231578

Log:
  MFC r229794:
  
  - Fix how hexdump parses escape strings
  From the NetBSD bug:
  The way how hexdump(1) parses escape sequences has some bugs.
  It shows up when an escape sequence is used as the non-last character
  of a format string.
  
  MFC r230649:
  
  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.
  
  PR:           bin/144722

Modified:
  stable/9/usr.bin/hexdump/parse.c
Directory Properties:
  stable/9/usr.bin/hexdump/   (props changed)

Modified: stable/9/usr.bin/hexdump/parse.c
==============================================================================
--- stable/9/usr.bin/hexdump/parse.c    Mon Feb 13 10:24:22 2012        
(r231577)
+++ stable/9/usr.bin/hexdump/parse.c    Mon Feb 13 10:24:49 2012        
(r231578)
@@ -255,7 +255,9 @@ rewrite(FS *fs)
                                        sokay = NOTOKAY;
                        }
 
-                       p2 = p1 + 1;            /* Set end pointer. */
+                       p2 = *p1 ? p1 + 1 : p1; /* Set end pointer -- make sure
+                                                * that it's non-NUL/-NULL first
+                                                * though. */
                        cs[0] = *p1;            /* Set conversion string. */
                        cs[1] = '\0';
 
@@ -449,13 +451,14 @@ escape(char *p1)
        char *p2;
 
        /* alphabetic escape sequences have to be done in place */
-       for (p2 = p1;; ++p1, ++p2) {
-               if (!*p1) {
-                       *p2 = *p1;
-                       break;
-               }
-               if (*p1 == '\\')
-                       switch(*++p1) {
+       for (p2 = p1;; p1++, p2++) {
+               if (*p1 == '\\') {
+                       p1++;
+                       switch(*p1) {
+                       case '\0':
+                               *p2 = '\\';
+                               *++p2 = '\0';
+                               return;
                        case 'a':
                             /* *p2 = '\a'; */
                                *p2 = '\007';
@@ -482,6 +485,11 @@ escape(char *p1)
                                *p2 = *p1;
                                break;
                        }
+               } else {
+                       *p2 = *p1;
+                       if (*p1 == '\0')
+                               return;
+               }
        }
 }
 
_______________________________________________
svn-src-all@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"

Reply via email to