make sure hostname and username have no surrogate escapes

if they are present, process them through json_text().
this replaces s-e by "?" for the key and puts the binary
representation into key_b64, if needed.

likely this is rarely needed.
This commit is contained in:
Thomas Waldmann 2023-01-19 20:46:40 +01:00
parent d090826a37
commit b3da7d0e72
No known key found for this signature in database
GPG Key ID: 243ACFA951F78E01
1 changed files with 11 additions and 6 deletions

View File

@ -715,9 +715,9 @@ class ArchiveFormatter(BaseFormatter):
self.format = partial_format(format, static_keys) self.format = partial_format(format, static_keys)
self.format_keys = {f[1] for f in Formatter().parse(format)} self.format_keys = {f[1] for f in Formatter().parse(format)}
self.call_keys = { self.call_keys = {
"hostname": partial(self.get_meta, "hostname", rs=True), "hostname": partial(self.get_meta, "hostname"),
"username": partial(self.get_meta, "username", rs=True), "username": partial(self.get_meta, "username"),
"comment": partial(self.get_meta, "comment", rs=False), "comment": partial(self.get_meta, "comment"),
"end": self.get_ts_end, "end": self.get_ts_end,
"command_line": self.get_cmdline, "command_line": self.get_cmdline,
} }
@ -747,6 +747,12 @@ class ArchiveFormatter(BaseFormatter):
) )
for key in self.used_call_keys: for key in self.used_call_keys:
item_data[key] = self.call_keys[key]() item_data[key] = self.call_keys[key]()
# Note: name and comment are validated, should never contain surrogate escapes.
# But unsure whether hostname, username could contain surrogate escapes, play safe:
for key in "hostname", "username":
if key in item_data:
item_data.update(text_to_json(key, item_data[key]))
return item_data return item_data
@property @property
@ -758,9 +764,8 @@ class ArchiveFormatter(BaseFormatter):
self._archive = Archive(self.manifest, self.name, iec=self.iec) self._archive = Archive(self.manifest, self.name, iec=self.iec)
return self._archive return self._archive
def get_meta(self, key, rs): def get_meta(self, key):
value = self.archive.metadata.get(key, "") return self.archive.metadata.get(key, "")
return remove_surrogates(value) if rs else value
def get_cmdline(self): def get_cmdline(self):
cmdline = map(remove_surrogates, self.archive.metadata.get("cmdline", [])) cmdline = map(remove_surrogates, self.archive.metadata.get("cmdline", []))