|
Zbigniew Jędrzejewski-Szmek |
436654 |
From c47edbd3bfaf64ad8fa3d105029bed8667baf275 Mon Sep 17 00:00:00 2001
|
|
Zbigniew Jędrzejewski-Szmek |
436654 |
From: Daniel Mack <daniel@zonque.org>
|
|
Zbigniew Jędrzejewski-Szmek |
436654 |
Date: Wed, 3 Jun 2015 13:33:26 +0200
|
|
Zbigniew Jędrzejewski-Szmek |
436654 |
Subject: [PATCH] util: fix another cunescape() regression
|
|
Zbigniew Jędrzejewski-Szmek |
436654 |
|
|
Zbigniew Jędrzejewski-Szmek |
436654 |
Fix a regression caused by 4034a06d ("util: rework word parsing and c
|
|
Zbigniew Jędrzejewski-Szmek |
436654 |
unescaping code") which broke octal escape sequences.
|
|
Zbigniew Jędrzejewski-Szmek |
436654 |
|
|
Zbigniew Jędrzejewski-Szmek |
436654 |
The reason for this breakage is that cunescape_one() expects 4 characters
|
|
Zbigniew Jędrzejewski-Szmek |
436654 |
in an octal encoding, which is a stray left-over from the old code which
|
|
Zbigniew Jędrzejewski-Szmek |
436654 |
operated on different variables to make the length check.
|
|
Zbigniew Jędrzejewski-Szmek |
436654 |
|
|
Zbigniew Jędrzejewski-Szmek |
436654 |
While at it, add a test case to prevent the same thing from happening
|
|
Zbigniew Jędrzejewski-Szmek |
436654 |
again.
|
|
Zbigniew Jędrzejewski-Szmek |
436654 |
|
|
Zbigniew Jędrzejewski-Szmek |
436654 |
(cherry picked from commit 3b51f8ddd5408eaae06e774e40144c7788748000)
|
|
Zbigniew Jędrzejewski-Szmek |
436654 |
---
|
|
Zbigniew Jędrzejewski-Szmek |
436654 |
src/shared/util.c | 2 +-
|
|
Zbigniew Jędrzejewski-Szmek |
436654 |
src/test/test-util.c | 3 +++
|
|
Zbigniew Jędrzejewski-Szmek |
436654 |
2 files changed, 4 insertions(+), 1 deletion(-)
|
|
Zbigniew Jędrzejewski-Szmek |
436654 |
|
|
Zbigniew Jędrzejewski-Szmek |
436654 |
diff --git a/src/shared/util.c b/src/shared/util.c
|
|
Zbigniew Jędrzejewski-Szmek |
436654 |
index 74a2190031..57782ba687 100644
|
|
Zbigniew Jędrzejewski-Szmek |
436654 |
--- a/src/shared/util.c
|
|
Zbigniew Jędrzejewski-Szmek |
436654 |
+++ b/src/shared/util.c
|
|
Zbigniew Jędrzejewski-Szmek |
436654 |
@@ -1186,7 +1186,7 @@ static int cunescape_one(const char *p, size_t length, char *ret, uint32_t *ret_
|
|
Zbigniew Jędrzejewski-Szmek |
436654 |
int a, b, c;
|
|
Zbigniew Jędrzejewski-Szmek |
436654 |
uint32_t m;
|
|
Zbigniew Jędrzejewski-Szmek |
436654 |
|
|
Zbigniew Jędrzejewski-Szmek |
436654 |
- if (length != (size_t) -1 && length < 4)
|
|
Zbigniew Jędrzejewski-Szmek |
436654 |
+ if (length != (size_t) -1 && length < 3)
|
|
Zbigniew Jędrzejewski-Szmek |
436654 |
return -EINVAL;
|
|
Zbigniew Jędrzejewski-Szmek |
436654 |
|
|
Zbigniew Jędrzejewski-Szmek |
436654 |
a = unoctchar(p[0]);
|
|
Zbigniew Jędrzejewski-Szmek |
436654 |
diff --git a/src/test/test-util.c b/src/test/test-util.c
|
|
Zbigniew Jędrzejewski-Szmek |
436654 |
index 36773c109d..fab485fa14 100644
|
|
Zbigniew Jędrzejewski-Szmek |
436654 |
--- a/src/test/test-util.c
|
|
Zbigniew Jędrzejewski-Szmek |
436654 |
+++ b/src/test/test-util.c
|
|
Zbigniew Jędrzejewski-Szmek |
436654 |
@@ -459,6 +459,9 @@ static void test_cunescape(void) {
|
|
Zbigniew Jędrzejewski-Szmek |
436654 |
assert_se(cunescape("\\u0000", 0, &unescaped) < 0);
|
|
Zbigniew Jędrzejewski-Szmek |
436654 |
assert_se(cunescape("\\u00DF\\U000000df\\u03a0\\U00000041", UNESCAPE_RELAX, &unescaped) >= 0);
|
|
Zbigniew Jędrzejewski-Szmek |
436654 |
assert_se(streq_ptr(unescaped, "ßßΠA"));
|
|
Zbigniew Jędrzejewski-Szmek |
436654 |
+
|
|
Zbigniew Jędrzejewski-Szmek |
436654 |
+ assert_se(cunescape("\\073", 0, &unescaped) >= 0);
|
|
Zbigniew Jędrzejewski-Szmek |
436654 |
+ assert_se(streq_ptr(unescaped, ";"));
|
|
Zbigniew Jędrzejewski-Szmek |
436654 |
}
|
|
Zbigniew Jędrzejewski-Szmek |
436654 |
|
|
Zbigniew Jędrzejewski-Szmek |
436654 |
static void test_foreach_word(void) {
|