1
1
mirror of https://github.com/systemd/systemd-stable.git synced 2025-01-08 21:17:47 +03:00

journald: fix followup comments on regex feature

Fix followup comments on PR #24058:
- Use `mempcpy_safe()`.
- Remove unused `pcre2_code` variable.
- Use `static const` when relevant.
This commit is contained in:
Quentin Deslandes 2023-01-06 09:15:55 +01:00 committed by Lennart Poettering
parent 34680637e8
commit 48d8516043
4 changed files with 10 additions and 10 deletions

View File

@ -785,6 +785,7 @@ int cgroup_log_xattr_apply(Unit *u, const char *cgroup_path) {
ExecContext *c;
size_t len, allowed_patterns_len, denied_patterns_len;
_cleanup_free_ char *patterns = NULL, *allowed_patterns = NULL, *denied_patterns = NULL;
char *last;
int r;
assert(u);
@ -817,9 +818,9 @@ int cgroup_log_xattr_apply(Unit *u, const char *cgroup_path) {
if (!patterns)
return log_oom_debug();
memcpy_safe(patterns, allowed_patterns, allowed_patterns_len);
patterns[allowed_patterns_len] = '\xff';
memcpy_safe(&patterns[allowed_patterns_len + 1], denied_patterns, denied_patterns_len);
last = mempcpy_safe(patterns, allowed_patterns, allowed_patterns_len);
*(last++) = '\xff';
memcpy_safe(last, denied_patterns, denied_patterns_len);
unit_set_xattr_graceful(u, cgroup_path, "user.journald_log_filter_patterns", patterns, len);

View File

@ -6505,7 +6505,6 @@ int config_parse_log_filter_patterns(
void *userdata) {
ExecContext *c = ASSERT_PTR(data);
_cleanup_(pattern_freep) pcre2_code *compiled_pattern = NULL;
const char *pattern = ASSERT_PTR(rvalue);
bool is_allowlist = true;
int r;
@ -6529,7 +6528,7 @@ int config_parse_log_filter_patterns(
"Regex pattern invalid, ignoring: %s=%s", lvalue, rvalue);
}
if (pattern_compile_and_log(pattern, 0, &compiled_pattern) < 0)
if (pattern_compile_and_log(pattern, 0, NULL) < 0)
return 0;
r = set_put_strdup(is_allowlist ? &c->log_filter_allowed_patterns : &c->log_filter_denied_patterns,

View File

@ -52,7 +52,7 @@ int dlopen_pcre2(void) {
int pattern_compile_and_log(const char *pattern, PatternCompileCase case_, pcre2_code **ret) {
#if HAVE_PCRE2
PCRE2_SIZE erroroffset;
pcre2_code *p;
_cleanup_(sym_pcre2_code_freep) pcre2_code *p = NULL;
unsigned flags = 0;
int errorcode, r;
@ -100,7 +100,7 @@ int pattern_compile_and_log(const char *pattern, PatternCompileCase case_, pcre2
}
if (ret)
*ret = p;
*ret = TAKE_PTR(p);
return 0;
#else

View File

@ -137,7 +137,7 @@ TEST(set_make_nulstr) {
{
/* Unallocated and empty set. */
char expect[] = { 0x00, 0x00 };
static const char expect[] = { 0x00, 0x00 };
_cleanup_free_ char *nulstr = NULL;
r = set_make_nulstr(set, &nulstr, &len);
@ -148,7 +148,7 @@ TEST(set_make_nulstr) {
{
/* Allocated by empty set. */
char expect[] = { 0x00, 0x00 };
static const char expect[] = { 0x00, 0x00 };
_cleanup_free_ char *nulstr = NULL;
set = set_new(NULL);
@ -162,7 +162,7 @@ TEST(set_make_nulstr) {
{
/* Non-empty set. */
char expect[] = { 'a', 'a', 'a', 0x00, 0x00 };
static const char expect[] = { 'a', 'a', 'a', 0x00, 0x00 };
_cleanup_free_ char *nulstr = NULL;
assert_se(set_put_strdup(&set, "aaa") >= 0);