mirror of
https://github.com/systemd/systemd-stable.git
synced 2025-01-11 05:17:44 +03:00
xdg-autostart: ignore all empty entries in multi-string entries
The desktop file specification allows entries like ";;;;;;", full of empty strings. But looking at the actual list of supported keys [1], empty entries are meaningless (unless we would allow e.g. the desktop name to be the empty string. But that doesn't seem very useful either). So let's just simplify our life and skip any empty substrings entirely. This would also resolve the fuzzer case: $ valgrind build/fuzz-xdg-desktop test/fuzz/fuzz-xdg-desktop/oss-fuzz-22812 test/fuzz/fuzz-xdg-desktop/oss-fuzz-22812... ok ==2899241== HEAP SUMMARY: ==2899241== in use at exit: 0 bytes in 0 blocks ==2899241== total heap usage: 484,385 allocs, 484,385 frees, 12,411,330 bytes allocated ↓ ==2899650== HEAP SUMMARY: ==2899650== in use at exit: 0 bytes in 0 blocks ==2899650== total heap usage: 1,325 allocs, 1,325 frees, 1,463,602 bytes allocated
This commit is contained in:
parent
d1ca1f7c2a
commit
dea7f5cc87
@ -67,7 +67,7 @@ static void test_xdg_desktop_parse(unsigned i, const char *s) {
|
||||
case 0:
|
||||
assert_se(streq(service->exec_string, "/bin/sleep 100"));
|
||||
assert_se(strv_equal(service->only_show_in, STRV_MAKE("A", "B")));
|
||||
assert_se(strv_equal(service->not_show_in, STRV_MAKE("C", "", "D\\;", "E")));
|
||||
assert_se(strv_equal(service->not_show_in, STRV_MAKE("C", "D\\;", "E")));
|
||||
assert_se(!service->hidden);
|
||||
break;
|
||||
case 1:
|
||||
@ -81,14 +81,12 @@ static void test_xdg_desktop_parse(unsigned i, const char *s) {
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
size_t i;
|
||||
|
||||
test_setup_logging(LOG_DEBUG);
|
||||
|
||||
test_translate_name();
|
||||
test_xdg_format_exec_start();
|
||||
|
||||
for (i = 0; i < ELEMENTSOF(xdg_desktop_file); i++)
|
||||
for (size_t i = 0; i < ELEMENTSOF(xdg_desktop_file); i++)
|
||||
test_xdg_desktop_parse(i, xdg_desktop_file[i]);
|
||||
|
||||
return 0;
|
||||
|
@ -192,6 +192,9 @@ static int strv_strndup_unescape_and_push(
|
||||
const char *start,
|
||||
const char *end) {
|
||||
|
||||
if (end == start)
|
||||
return 0;
|
||||
|
||||
_cleanup_free_ char *copy = NULL;
|
||||
int r;
|
||||
|
||||
@ -270,14 +273,12 @@ static int xdg_config_parse_strv(
|
||||
}
|
||||
}
|
||||
|
||||
/* Any trailing entry should be ignored if it is empty. */
|
||||
if (end > start) {
|
||||
r = strv_strndup_unescape_and_push(unit, filename, line,
|
||||
&sv, &n_allocated, &n,
|
||||
start, end);
|
||||
if (r < 0)
|
||||
return r;
|
||||
}
|
||||
/* Handle the trailing entry after the last separator */
|
||||
r = strv_strndup_unescape_and_push(unit, filename, line,
|
||||
&sv, &n_allocated, &n,
|
||||
start, end);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
*ret_sv = TAKE_PTR(sv);
|
||||
return 0;
|
||||
|
Loading…
Reference in New Issue
Block a user