summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorQuentin Deslandes <qde@naccy.de>2023-01-06 09:15:55 +0100
committerLennart Poettering <lennart@poettering.net>2023-01-06 14:59:31 +0100
commit48d85160438827c1424104315547f960ec0d6e43 (patch)
treea39d805102c34555ab80314839f5379afa57e37d
parent34680637e838415204850f77c93ca6ca219abaf1 (diff)
downloadsystemd-48d85160438827c1424104315547f960ec0d6e43.tar.gz
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.
-rw-r--r--src/core/cgroup.c7
-rw-r--r--src/core/load-fragment.c3
-rw-r--r--src/shared/pcre2-util.c4
-rw-r--r--src/test/test-nulstr-util.c6
4 files changed, 10 insertions, 10 deletions
diff --git a/src/core/cgroup.c b/src/core/cgroup.c
index 2d671566ac..e04b903d5c 100644
--- a/src/core/cgroup.c
+++ b/src/core/cgroup.c
@@ -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);
diff --git a/src/core/load-fragment.c b/src/core/load-fragment.c
index e5766a58a7..24d402b6e5 100644
--- a/src/core/load-fragment.c
+++ b/src/core/load-fragment.c
@@ -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,
diff --git a/src/shared/pcre2-util.c b/src/shared/pcre2-util.c
index a2c8687cf9..578b02ddc0 100644
--- a/src/shared/pcre2-util.c
+++ b/src/shared/pcre2-util.c
@@ -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
diff --git a/src/test/test-nulstr-util.c b/src/test/test-nulstr-util.c
index 1b7e4c1db1..70f1e8705d 100644
--- a/src/test/test-nulstr-util.c
+++ b/src/test/test-nulstr-util.c
@@ -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);