uapi16-manifest: treat an empty "literal" field as set

The "literal" field of a contents object may carry empty data, which
encodes an empty file. iovec_is_set() returns false for that though, so
such a field was considered absent, and the check that "file", "url"
and "literal" are mutually exclusive did not refuse an empty "literal"
next to one of the others.

Add uapi16_contents_has_literal(), which checks whether the field was
set instead of whether it carries data, and use it for the check.
This commit is contained in:
Lennart Poettering committed 2026-11-05 08:32:14 +01:00
1 parent 85007a1719
commit 6ccf8b794b
2 files changed
+8 -1

No files matched your search

+1 -1
View File
@@ -536,7 +536,7 @@ static int json_dispatch_contents(const char *name, sd_json_variant *variant, sd
if (r < 0)
return r;
if (!!c.file + !!c.url + !!iovec_is_set(&c.literal) > 1)
if (!!c.file + !!c.url + uapi16_contents_has_literal(&c) > 1)
return json_log(variant, flags, SYNTHETIC_ERRNO(EINVAL), "Only one of 'file', 'url', 'literal' may be set for '%s'.", strna(name));
if (c.encoding) {
+7
View File
@@ -26,6 +26,13 @@ typedef struct Uapi16Contents {
.original_size = UINT64_MAX, \
}
static inline bool uapi16_contents_has_literal(const Uapi16Contents *c) {
/* An empty "literal" field is valid (it encodes empty data), hence check whether the field was set,
* not whether it carries data: when decoding Base64 we always allocate a buffer, even for empty
* data. */
return c->literal.iov_base;
}
/* An extended attribute in the "user" namespace */
typedef struct Uapi16Xattr {
char *name; /* The attribute name, without the "user." prefix */