]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
util: fix another cunescape() regression 51/head
authorDaniel Mack <daniel@zonque.org>
Wed, 3 Jun 2015 11:33:26 +0000 (13:33 +0200)
committerDaniel Mack <daniel@zonque.org>
Wed, 3 Jun 2015 11:54:21 +0000 (13:54 +0200)
Fix a regression caused by 4034a06d ("util: rework word parsing and c
unescaping code") which broke octal escape sequences.

The reason for this breakage is that cunescape_one() expects 4 characters
in an octal encoding, which is a stray left-over from the old code which
operated on different variables to make the length check.

While at it, add a test case to prevent the same thing from happening
again.

src/shared/util.c
src/test/test-util.c

index 8a6107969ae1cacc51fe0ef19261ba8834fcfec9..311acbb3499384c5d28df4a9ee5a7b13a049e7db 100644 (file)
@@ -1152,7 +1152,7 @@ static int cunescape_one(const char *p, size_t length, char *ret, uint32_t *ret_
                 int a, b, c;
                 uint32_t m;
 
-                if (length != (size_t) -1 && length < 4)
+                if (length != (size_t) -1 && length < 3)
                         return -EINVAL;
 
                 a = unoctchar(p[0]);
index e0269821d79dac4801ad30f473165ddbc3341640..7a398fafbe45befdf278649e6ca1c19ef4f03659 100644 (file)
@@ -460,6 +460,9 @@ static void test_cunescape(void) {
         assert_se(cunescape("\\u0000", 0, &unescaped) < 0);
         assert_se(cunescape("\\u00DF\\U000000df\\u03a0\\U00000041", UNESCAPE_RELAX, &unescaped) >= 0);
         assert_se(streq_ptr(unescaped, "ßßΠA"));
+
+        assert_se(cunescape("\\073", 0, &unescaped) >= 0);
+        assert_se(streq_ptr(unescaped, ";"));
 }
 
 static void test_foreach_word(void) {