tree-wide: refuse too long strings earlier in specifier_printf()
We usually call specifier_printf() and then check the validity of the result. In many cases, validity checkers, e.g. path_is_valid(), refuse too long strings. This makes specifier_printf() refuse such long results earlier. Moreover, unit_full_string() and description field in sysuser now refuse results longer than LONG_LINE_MAX. config_parse() already refuses the line longer than LONG_LINE_MAX. Hence, it should be ok to set the same value as the maximum length of the resolved string.
This commit is contained in:
@@ -1492,7 +1492,7 @@ static int parse_line(const char *fname, unsigned line, const char *buffer) {
|
||||
name = mfree(name);
|
||||
|
||||
if (name) {
|
||||
r = specifier_printf(name, specifier_table, NULL, &resolved_name);
|
||||
r = specifier_printf(name, NAME_MAX, specifier_table, NULL, &resolved_name);
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "[%s:%u] Failed to replace specifiers in '%s': %m", fname, line, name);
|
||||
|
||||
@@ -1507,7 +1507,7 @@ static int parse_line(const char *fname, unsigned line, const char *buffer) {
|
||||
id = mfree(id);
|
||||
|
||||
if (id) {
|
||||
r = specifier_printf(id, specifier_table, NULL, &resolved_id);
|
||||
r = specifier_printf(id, PATH_MAX-1, specifier_table, NULL, &resolved_id);
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "[%s:%u] Failed to replace specifiers in '%s': %m",
|
||||
fname, line, name);
|
||||
@@ -1518,7 +1518,7 @@ static int parse_line(const char *fname, unsigned line, const char *buffer) {
|
||||
description = mfree(description);
|
||||
|
||||
if (description) {
|
||||
r = specifier_printf(description, specifier_table, NULL, &resolved_description);
|
||||
r = specifier_printf(description, LONG_LINE_MAX, specifier_table, NULL, &resolved_description);
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "[%s:%u] Failed to replace specifiers in '%s': %m",
|
||||
fname, line, description);
|
||||
@@ -1534,7 +1534,7 @@ static int parse_line(const char *fname, unsigned line, const char *buffer) {
|
||||
home = mfree(home);
|
||||
|
||||
if (home) {
|
||||
r = specifier_printf(home, specifier_table, NULL, &resolved_home);
|
||||
r = specifier_printf(home, PATH_MAX-1, specifier_table, NULL, &resolved_home);
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "[%s:%u] Failed to replace specifiers in '%s': %m",
|
||||
fname, line, home);
|
||||
@@ -1550,7 +1550,7 @@ static int parse_line(const char *fname, unsigned line, const char *buffer) {
|
||||
shell = mfree(shell);
|
||||
|
||||
if (shell) {
|
||||
r = specifier_printf(shell, specifier_table, NULL, &resolved_shell);
|
||||
r = specifier_printf(shell, PATH_MAX-1, specifier_table, NULL, &resolved_shell);
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "[%s:%u] Failed to replace specifiers in '%s': %m",
|
||||
fname, line, shell);
|
||||
|
||||
Reference in New Issue
Block a user