[systemd-commits] src/shared src/test

Lennart Poettering lennart at kemper.freedesktop.org
Fri Apr 10 02:57:05 PDT 2015


 src/shared/util.c    |   12 ++++++------
 src/test/test-util.c |   11 +++++++++++
 2 files changed, 17 insertions(+), 6 deletions(-)

New commits:
commit 8ebac1f9a681ce1c6287e7c6a1b3093b00fb0c5a
Author: Lennart Poettering <lennart at poettering.net>
Date:   Fri Apr 10 11:56:04 2015 +0200

    util: fix unicode decoding in unquote_first_word()

diff --git a/src/shared/util.c b/src/shared/util.c
index 2385224..61f3090 100644
--- a/src/shared/util.c
+++ b/src/shared/util.c
@@ -7284,7 +7284,7 @@ int unquote_first_word(const char **p, char **ret, UnquoteFlags flags) {
                                 return -EINVAL;
                         }
 
-                        if (!GREEDY_REALLOC(s, allocated, sz+2))
+                        if (!GREEDY_REALLOC(s, allocated, sz+7))
                                 return -ENOMEM;
 
                         if (flags & UNQUOTE_CUNESCAPE) {
@@ -7299,7 +7299,7 @@ int unquote_first_word(const char **p, char **ret, UnquoteFlags flags) {
                                 if (c != 0)
                                         s[sz++] = c; /* normal explicit char */
                                 else
-                                        sz += utf8_encode_unichar(s, u); /* unicode chars we'll encode as utf8 */
+                                        sz += utf8_encode_unichar(s + sz, u); /* unicode chars we'll encode as utf8 */
                         } else
                                 s[sz++] = c;
 
@@ -7331,7 +7331,7 @@ int unquote_first_word(const char **p, char **ret, UnquoteFlags flags) {
                                 return -EINVAL;
                         }
 
-                        if (!GREEDY_REALLOC(s, allocated, sz+2))
+                        if (!GREEDY_REALLOC(s, allocated, sz+7))
                                 return -ENOMEM;
 
                         if (flags & UNQUOTE_CUNESCAPE) {
@@ -7346,7 +7346,7 @@ int unquote_first_word(const char **p, char **ret, UnquoteFlags flags) {
                                 if (c != 0)
                                         s[sz++] = c;
                                 else
-                                        sz += utf8_encode_unichar(s, u);
+                                        sz += utf8_encode_unichar(s + sz, u);
                         } else
                                 s[sz++] = c;
 
@@ -7376,7 +7376,7 @@ int unquote_first_word(const char **p, char **ret, UnquoteFlags flags) {
                                 return -EINVAL;
                         }
 
-                        if (!GREEDY_REALLOC(s, allocated, sz+2))
+                        if (!GREEDY_REALLOC(s, allocated, sz+7))
                                 return -ENOMEM;
 
                         if (flags & UNQUOTE_CUNESCAPE) {
@@ -7391,7 +7391,7 @@ int unquote_first_word(const char **p, char **ret, UnquoteFlags flags) {
                                 if (c != 0)
                                         s[sz++] = c;
                                 else
-                                        sz += utf8_encode_unichar(s, u);
+                                        sz += utf8_encode_unichar(s + sz, u);
                         } else
                                 s[sz++] = c;
 
diff --git a/src/test/test-util.c b/src/test/test-util.c
index 7af41bc..77e7400 100644
--- a/src/test/test-util.c
+++ b/src/test/test-util.c
@@ -1376,6 +1376,17 @@ static void test_unquote_first_word(void) {
         assert_se(streq(t, "foobax6ar"));
         free(t);
         assert_se(p == original + 13);
+
+        p = original = "    f\\u00f6o \"pi\\U0001F4A9le\"   ";
+        assert_se(unquote_first_word(&p, &t, UNQUOTE_CUNESCAPE) > 0);
+        assert_se(streq(t, "föo"));
+        free(t);
+        assert_se(p == original + 13);
+
+        assert_se(unquote_first_word(&p, &t, UNQUOTE_CUNESCAPE) > 0);
+        assert_se(streq(t, "pi\360\237\222\251le"));
+        free(t);
+        assert_se(p == original + 32);
 }
 
 static void test_unquote_many_words(void) {



More information about the systemd-commits mailing list