1
0
mirror of https://github.com/systemd/systemd.git synced 2025-03-10 16:58:28 +03:00

shared/open-file: use xescape to escape ':'

Fixes #32179
This commit is contained in:
Mike Yuan 2024-04-09 21:54:30 +08:00
parent 4eb1feb110
commit c1f9509f79
No known key found for this signature in database
GPG Key ID: 417471C0A40F58B3
2 changed files with 5 additions and 7 deletions

View 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;

View 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);