]> granicus.if.org Git - nethack/commitdiff
fix sym_val() buffer overrun fix
authorPatR <rankin@nethack.org>
Tue, 14 Jan 2020 22:34:03 +0000 (14:34 -0800)
committerPatR <rankin@nethack.org>
Tue, 14 Jan 2020 22:34:03 +0000 (14:34 -0800)
Fix a mistake in commit 74de7d31e0a6b3e2ebd852e333fe66d212fd6a90.
Copy+paste error resulted in 'strval + 1' when 'strval' is required.

src/options.c

index 1f8477193b4ceae470866f0d1c57637e140b987c..8b56a87a3c8561b34b489c390daaab9536581ded 100644 (file)
@@ -6202,6 +6202,7 @@ const char *strval; /* up to 4*BUFSZ-1 long; only first few chars matter */
         } else {
             char *p;
 
+            /* +1: skip opening single quote */
             (void) strncpy(tmp, strval + 1, sizeof tmp - 1);
             tmp[sizeof tmp - 1] = '\0';
             if ((p = rindex(tmp, '\'')) != 0) {
@@ -6210,7 +6211,7 @@ const char *strval; /* up to 4*BUFSZ-1 long; only first few chars matter */
             } /* else buf[0] stays '\0' */
         }
     } else { /* not lone char nor single quote */
-        (void) strncpy(tmp, strval + 1, sizeof tmp - 1);
+        (void) strncpy(tmp, strval, sizeof tmp - 1);
         tmp[sizeof tmp - 1] = '\0';
         escapes(tmp, buf);
     }