1
0
mirror of https://github.com/systemd/systemd.git synced 2024-12-25 01:34:28 +03:00

journal: fix export of messages containing newlines

In "export" format, newlines are significant, and messages containing
newlines must be exported as "binary".
This commit is contained in:
Zbigniew Jędrzejewski-Szmek 2014-03-31 08:57:28 -04:00
parent a36b8debe6
commit 0ade5ffe27
Notes: Zbigniew Jędrzejewski-Szmek 2014-04-07 12:29:44 -04:00
Backport: bugfix
3 changed files with 11 additions and 6 deletions

View File

@ -547,7 +547,9 @@ static int output_export(
startswith(data, "_BOOT_ID="))
continue;
if (!utf8_is_printable(data, length)) {
if (utf8_is_printable_newline(data, length, false))
fwrite(data, length, 1, f);
else {
const char *c;
uint64_t le64;
@ -562,8 +564,7 @@ static int output_export(
le64 = htole64(length - (c - (const char*) data) - 1);
fwrite(&le64, sizeof(le64), 1, f);
fwrite(c + 1, length - (c - (const char*) data) - 1, 1, f);
} else
fwrite(data, length, 1, f);
}
fputc('\n', f);
}

View File

@ -136,7 +136,7 @@ int utf8_encoded_to_unichar(const char *str) {
return unichar;
}
bool utf8_is_printable(const char* str, size_t length) {
bool utf8_is_printable_newline(const char* str, size_t length, bool newline) {
const uint8_t *p;
assert(str);
@ -145,7 +145,8 @@ bool utf8_is_printable(const char* str, size_t length) {
int encoded_len = utf8_encoded_valid_unichar((const char *)p);
int val = utf8_encoded_to_unichar((const char*)p);
if (encoded_len < 0 || val < 0 || is_unicode_control(val))
if (encoded_len < 0 || val < 0 || is_unicode_control(val) ||
(!newline && val == '\n'))
return false;
length -= encoded_len;

View File

@ -31,7 +31,10 @@ const char *utf8_is_valid(const char *s) _pure_;
char *ascii_is_valid(const char *s) _pure_;
char *utf8_escape_invalid(const char *s);
bool utf8_is_printable(const char* str, size_t length) _pure_;
bool utf8_is_printable_newline(const char* str, size_t length, bool newline) _pure_;
_pure_ static inline bool utf8_is_printable(const char* str, size_t length) {
return utf8_is_printable_newline(str, length, true);
}
char *utf16_to_utf8(const void *s, size_t length);