Merge pull request #17799 from yuwata/oss-fuzz-25353
logs-show: skip non-utf8 name entries
This commit is contained in:
commit
199f75205b
|
@ -24,7 +24,7 @@
|
|||
#include "hexdecoct.h"
|
||||
#include "io-util.h"
|
||||
#include "ioprio.h"
|
||||
#include "journal-util.h"
|
||||
#include "journal-file.h"
|
||||
#include "mountpoint-util.h"
|
||||
#include "namespace.h"
|
||||
#include "parse-util.h"
|
||||
|
|
|
@ -38,7 +38,7 @@
|
|||
#include "io-util.h"
|
||||
#include "ioprio.h"
|
||||
#include "ip-protocol-list.h"
|
||||
#include "journal-util.h"
|
||||
#include "journal-file.h"
|
||||
#include "limits-util.h"
|
||||
#include "load-fragment.h"
|
||||
#include "log.h"
|
||||
|
|
|
@ -1521,6 +1521,44 @@ int journal_file_find_data_object(
|
|||
ret, ret_offset);
|
||||
}
|
||||
|
||||
bool journal_field_valid(const char *p, size_t l, bool allow_protected) {
|
||||
const char *a;
|
||||
|
||||
/* We kinda enforce POSIX syntax recommendations for
|
||||
environment variables here, but make a couple of additional
|
||||
requirements.
|
||||
|
||||
http://pubs.opengroup.org/onlinepubs/000095399/basedefs/xbd_chap08.html */
|
||||
|
||||
if (l == (size_t) -1)
|
||||
l = strlen(p);
|
||||
|
||||
/* No empty field names */
|
||||
if (l <= 0)
|
||||
return false;
|
||||
|
||||
/* Don't allow names longer than 64 chars */
|
||||
if (l > 64)
|
||||
return false;
|
||||
|
||||
/* Variables starting with an underscore are protected */
|
||||
if (!allow_protected && p[0] == '_')
|
||||
return false;
|
||||
|
||||
/* Don't allow digits as first character */
|
||||
if (p[0] >= '0' && p[0] <= '9')
|
||||
return false;
|
||||
|
||||
/* Only allow A-Z0-9 and '_' */
|
||||
for (a = p; a < p + l; a++)
|
||||
if ((*a < 'A' || *a > 'Z') &&
|
||||
(*a < '0' || *a > '9') &&
|
||||
*a != '_')
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static int journal_file_append_field(
|
||||
JournalFile *f,
|
||||
const void *field, uint64_t size,
|
||||
|
@ -1534,6 +1572,9 @@ static int journal_file_append_field(
|
|||
assert(f);
|
||||
assert(field && size > 0);
|
||||
|
||||
if (!journal_field_valid(field, size, true))
|
||||
return -EBADMSG;
|
||||
|
||||
hash = journal_file_hash_data(f, field, size);
|
||||
|
||||
r = journal_file_find_field_object_with_hash(f, field, size, hash, &o, &p);
|
||||
|
|
|
@ -271,3 +271,5 @@ static inline bool JOURNAL_FILE_COMPRESS(JournalFile *f) {
|
|||
}
|
||||
|
||||
uint64_t journal_file_hash_data(JournalFile *f, const void *data, size_t sz);
|
||||
|
||||
bool journal_field_valid(const char *p, size_t l, bool allow_protected);
|
||||
|
|
|
@ -137,41 +137,3 @@ int journal_access_check_and_warn(sd_journal *j, bool quiet, bool want_other_use
|
|||
|
||||
return r;
|
||||
}
|
||||
|
||||
bool journal_field_valid(const char *p, size_t l, bool allow_protected) {
|
||||
const char *a;
|
||||
|
||||
/* We kinda enforce POSIX syntax recommendations for
|
||||
environment variables here, but make a couple of additional
|
||||
requirements.
|
||||
|
||||
http://pubs.opengroup.org/onlinepubs/000095399/basedefs/xbd_chap08.html */
|
||||
|
||||
if (l == (size_t) -1)
|
||||
l = strlen(p);
|
||||
|
||||
/* No empty field names */
|
||||
if (l <= 0)
|
||||
return false;
|
||||
|
||||
/* Don't allow names longer than 64 chars */
|
||||
if (l > 64)
|
||||
return false;
|
||||
|
||||
/* Variables starting with an underscore are protected */
|
||||
if (!allow_protected && p[0] == '_')
|
||||
return false;
|
||||
|
||||
/* Don't allow digits as first character */
|
||||
if (p[0] >= '0' && p[0] <= '9')
|
||||
return false;
|
||||
|
||||
/* Only allow A-Z0-9 and '_' */
|
||||
for (a = p; a < p + l; a++)
|
||||
if ((*a < 'A' || *a > 'Z') &&
|
||||
(*a < '0' || *a > '9') &&
|
||||
*a != '_')
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -6,6 +6,5 @@
|
|||
|
||||
#include "sd-journal.h"
|
||||
|
||||
bool journal_field_valid(const char *p, size_t l, bool allow_protected);
|
||||
int journal_access_blocked(sd_journal *j);
|
||||
int journal_access_check_and_warn(sd_journal *j, bool quiet, bool want_other_users);
|
||||
|
|
|
@ -702,9 +702,11 @@ static int output_verbose(
|
|||
|
||||
c = memchr(data, '=', length);
|
||||
if (!c)
|
||||
return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
|
||||
"Invalid field.");
|
||||
return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "Invalid field.");
|
||||
|
||||
fieldlen = c - (const char*) data;
|
||||
if (!journal_field_valid(data, fieldlen, true))
|
||||
return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "Invalid field.");
|
||||
|
||||
r = field_set_test(output_fields, data, fieldlen);
|
||||
if (r < 0)
|
||||
|
@ -798,6 +800,7 @@ static int output_export(
|
|||
sd_id128_to_string(boot_id, sid));
|
||||
|
||||
JOURNAL_FOREACH_DATA_RETVAL(j, data, length, r) {
|
||||
size_t fieldlen;
|
||||
const char *c;
|
||||
|
||||
/* We already printed the boot id from the data in the header, hence let's suppress it here */
|
||||
|
@ -806,10 +809,13 @@ static int output_export(
|
|||
|
||||
c = memchr(data, '=', length);
|
||||
if (!c)
|
||||
return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
|
||||
"Invalid field.");
|
||||
return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "Invalid field.");
|
||||
|
||||
r = field_set_test(output_fields, data, c - (const char *) data);
|
||||
fieldlen = c - (const char*) data;
|
||||
if (!journal_field_valid(data, fieldlen, true))
|
||||
return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "Invalid field.");
|
||||
|
||||
r = field_set_test(output_fields, data, fieldlen);
|
||||
if (r < 0)
|
||||
return r;
|
||||
if (!r)
|
||||
|
@ -820,11 +826,11 @@ static int output_export(
|
|||
else {
|
||||
uint64_t le64;
|
||||
|
||||
fwrite(data, c - (const char*) data, 1, f);
|
||||
fwrite(data, fieldlen, 1, f);
|
||||
fputc('\n', f);
|
||||
le64 = htole64(length - (c - (const char*) data) - 1);
|
||||
le64 = htole64(length - fieldlen - 1);
|
||||
fwrite(&le64, sizeof(le64), 1, f);
|
||||
fwrite(c + 1, length - (c - (const char*) data) - 1, 1, f);
|
||||
fwrite(c + 1, length - fieldlen - 1, 1, f);
|
||||
}
|
||||
|
||||
fputc('\n', f);
|
||||
|
@ -961,6 +967,7 @@ static int update_json_data_split(
|
|||
const void *data,
|
||||
size_t size) {
|
||||
|
||||
size_t fieldlen;
|
||||
const char *eq;
|
||||
char *name;
|
||||
|
||||
|
@ -974,14 +981,15 @@ static int update_json_data_split(
|
|||
if (!eq)
|
||||
return 0;
|
||||
|
||||
if (eq == data)
|
||||
return 0;
|
||||
fieldlen = eq - (const char*) data;
|
||||
if (!journal_field_valid(data, fieldlen, true))
|
||||
return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "Invalid field.");
|
||||
|
||||
name = strndupa(data, eq - (const char*) data);
|
||||
name = strndupa(data, fieldlen);
|
||||
if (output_fields && !set_contains(output_fields, name))
|
||||
return 0;
|
||||
|
||||
return update_json_data(h, flags, name, eq + 1, size - (eq - (const char*) data) - 1);
|
||||
return update_json_data(h, flags, name, eq + 1, size - fieldlen - 1);
|
||||
}
|
||||
|
||||
static int output_json(
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
#include "hexdecoct.h"
|
||||
#include "hostname-util.h"
|
||||
#include "in-addr-util.h"
|
||||
#include "journal-util.h"
|
||||
#include "journal-file.h"
|
||||
#include "list.h"
|
||||
#include "locale-util.h"
|
||||
#include "memory-util.h"
|
||||
|
|
BIN
test/fuzz/fuzz-journal-remote/oss-fuzz-25353
Normal file
BIN
test/fuzz/fuzz-journal-remote/oss-fuzz-25353
Normal file
Binary file not shown.
Loading…
Reference in a new issue