1
0
mirror of https://github.com/systemd/systemd.git synced 2024-10-30 14:55:37 +03:00

core: command argument can be longer than PATH_MAX

Fixes a bug introduced by 0653649202.

Fixes #22957.
This commit is contained in:
Yu Watanabe 2022-04-05 21:47:46 +09:00
parent c0da575a0e
commit 58dd4999dc
2 changed files with 17 additions and 1 deletions

View File

@ -1000,7 +1000,7 @@ int config_parse_exec(
if (r < 0) if (r < 0)
return ignore ? 0 : -ENOEXEC; return ignore ? 0 : -ENOEXEC;
r = unit_path_printf(u, word, &resolved); r = unit_full_printf(u, word, &resolved);
if (r < 0) { if (r < 0) {
log_syntax(unit, ignore ? LOG_WARNING : LOG_ERR, filename, line, r, log_syntax(unit, ignore ? LOG_WARNING : LOG_ERR, filename, line, r,
"Failed to resolve unit specifiers in %s%s: %m", "Failed to resolve unit specifiers in %s%s: %m",

View File

@ -10,6 +10,7 @@
#include "capability-util.h" #include "capability-util.h"
#include "conf-parser.h" #include "conf-parser.h"
#include "fd-util.h" #include "fd-util.h"
#include "fileio.h"
#include "format-util.h" #include "format-util.h"
#include "fs-util.h" #include "fs-util.h"
#include "hashmap.h" #include "hashmap.h"
@ -416,6 +417,21 @@ TEST(config_parse_exec) {
assert_se(r == 0); assert_se(r == 0);
assert_se(c1->command_next == NULL); assert_se(c1->command_next == NULL);
log_info("/* long arg */"); /* See issue #22957. */
char x[LONG_LINE_MAX-100], *y;
y = mempcpy(x, "/bin/echo ", STRLEN("/bin/echo "));
memset(y, 'x', sizeof(x) - STRLEN("/bin/echo ") - 1);
x[sizeof(x) - 1] = '\0';
r = config_parse_exec(NULL, "fake", 5, "section", 1,
"LValue", 0, x,
&c, u);
assert_se(r >= 0);
c1 = c1->command_next;
check_execcommand(c1,
"/bin/echo", NULL, y, NULL, false);
log_info("/* empty argument, reset */"); log_info("/* empty argument, reset */");
r = config_parse_exec(NULL, "fake", 4, "section", 1, r = config_parse_exec(NULL, "fake", 4, "section", 1,
"LValue", 0, "", "LValue", 0, "",