chiark / gitweb /
unit-name: Fix unescaping
authorTom Gundersen <teg@jklm.no>
Sat, 16 Oct 2010 22:11:23 +0000 (00:11 +0200)
committerLennart Poettering <lennart@poettering.net>
Thu, 21 Oct 2010 12:04:10 +0000 (14:04 +0200)
Invalid characters in unit names are escaped as \xFF. However, when
unescaping we were looking for \FF.

src/unit-name.c

index d0cfca6..debf2b2 100644 (file)
@@ -272,13 +272,13 @@ char *unit_name_unescape(const char *f) {
                 else if (*f == '\\') {
                         int a, b;
 
-                        if ((a = unhexchar(f[1])) < 0 ||
-                            (b = unhexchar(f[2])) < 0) {
-                                /* Invalid escape code, let's take it literal then */
+                        if (f[1] != 'x' || (a = unhexchar(f[2])) < 0 ||
+                                       (b = unhexchar(f[3])) < 0) {
+                               /* Invalid escape code, let's take it literal then */
                                 *(t++) = '\\';
                         } else {
                                 *(t++) = (char) ((a << 4) | b);
-                                f += 2;
+                                f += 3;
                         }
                 } else
                         *(t++) = *f;