portable: avoid passing through ID/version fields to LogExtraFields= when they contain control characters

Found by Claude Code Review.

Follow-up for e8114a4f86
This commit is contained in:
Luca Boccassi
2026-03-12 16:16:30 +00:00
parent 3df88e836c
commit cbea0e34c4

View File

@@ -1382,9 +1382,19 @@ static int append_release_log_fields(
/* Find an ID first, in order of preference from more specific to less specific: IMAGE_ID -> ID */
id = strv_find_first_field((char *const *)field_ids[type], fields);
if (id && string_has_cc(id, /* ok= */ NULL)) {
log_debug("os-release file '%s' contains control characters in the ID field, skipping.",
release->name);
id = NULL;
}
/* Then the version, same logic, prefer the more specific one */
version = strv_find_first_field((char *const *)field_versions[type], fields);
if (version && string_has_cc(version, /* ok= */ NULL)) {
log_debug("os-release file '%s' contains control characters in the version field, skipping.",
release->name);
version = NULL;
}
/* If there's no valid version to be found, simply omit it. */
if (!id && !version)