]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
shared/open-file: use xescape to escape ':'
authorMike Yuan <me@yhndnzj.com>
Tue, 9 Apr 2024 13:54:30 +0000 (21:54 +0800)
committerMike Yuan <me@yhndnzj.com>
Wed, 10 Apr 2024 12:16:35 +0000 (20:16 +0800)
Fixes #32179

src/shared/open-file.c
src/test/test-open-file.c

index 09062d8e6e13390befcad0a05bbde53ee4f5ed90..a9c2a11032742eb617f3e372608deaf1ac4b5313 100644 (file)
@@ -95,7 +95,7 @@ int open_file_to_string(const OpenFile *of, char **ret) {
         assert(of);
         assert(ret);
 
-        s = shell_escape(of->path, ":");
+        s = xescape(of->path, ":");
         if (!s)
                 return -ENOMEM;
 
index 1b938ec5f73df2398cec9b9dd8cdcaa9a56f724c..4c3ba57bc8c72d2f2c939b81267d654f91d7dbf2 100644 (file)
@@ -172,14 +172,12 @@ TEST(open_file_to_string) {
         assert_se(streq(s, "/proc/1/ns/mnt::read-only"));
 
         s = mfree(s);
-        assert_se(free_and_strdup(&of->path, "/path:with:colon"));
-        assert_se(free_and_strdup(&of->fdname, "path:with:colon"));
+        ASSERT_OK(free_and_strdup(&of->path, "/path:with:colon"));
+        ASSERT_OK(free_and_strdup(&of->fdname, "path:with:colon"));
         of->flags = 0;
 
-        r = open_file_to_string(of, &s);
-
-        assert_se(r >= 0);
-        assert_se(streq(s, "/path\\:with\\:colon"));
+        ASSERT_OK(open_file_to_string(of, &s));
+        ASSERT_STREQ(s, "/path\\x3awith\\x3acolon");
 }
 
 DEFINE_TEST_MAIN(LOG_INFO);