Whamcloud - gitweb
libsupport: improve how invalid hex strings are parsed as C strings
authorTheodore Ts'o <tytso@mit.edu>
Tue, 31 Jan 2017 20:30:28 +0000 (15:30 -0500)
committerTheodore Ts'o <tytso@mit.edu>
Tue, 31 Jan 2017 20:30:28 +0000 (15:30 -0500)
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
lib/support/cstring.c

index 3250477..7965e95 100644 (file)
@@ -52,7 +52,7 @@ int parse_c_string(char *str)
                                else if (ch >= 'A' && ch <= 'F')
                                        v = ch + 10 - 'A';
                                else {
-                                       ch = *from;
+                                       *to = 'x';
                                        break;
                                }
                                from++;
@@ -64,7 +64,8 @@ int parse_c_string(char *str)
                                else if (ch >= 'A' && ch <= 'F')
                                        v = (v * 16) + (ch + 10 - 'A');
                                else {
-                                       ch = *from;
+                                       *to = 'x';
+                                       from--;
                                        break;
                                }
                                from++;