From: Daniel Mack Date: Wed, 3 Jun 2015 11:33:26 +0000 (+0200) Subject: util: fix another cunescape() regression X-Git-Tag: v221~197^2 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=refs%2Fpull%2F51%2Fhead;p=thirdparty%2Fsystemd.git util: fix another cunescape() regression 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. --- diff --git a/src/shared/util.c b/src/shared/util.c index 8a6107969ae..311acbb3499 100644 --- a/src/shared/util.c +++ b/src/shared/util.c @@ -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]); diff --git a/src/test/test-util.c b/src/test/test-util.c index e0269821d79..7a398fafbe4 100644 --- a/src/test/test-util.c +++ b/src/test/test-util.c @@ -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) {