]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
journald: fix followup comments on regex feature
authorQuentin Deslandes <qde@naccy.de>
Fri, 6 Jan 2023 08:15:55 +0000 (09:15 +0100)
committerLennart Poettering <lennart@poettering.net>
Fri, 6 Jan 2023 13:59:31 +0000 (14:59 +0100)
Fix followup comments on PR #24058:
- Use `mempcpy_safe()`.
- Remove unused `pcre2_code` variable.
- Use `static const` when relevant.

src/core/cgroup.c
src/core/load-fragment.c
src/shared/pcre2-util.c
src/test/test-nulstr-util.c

index 2d671566ac836c914af60479cc1b1020b992d36b..e04b903d5c85273b1e009b535425bc1cfe9d8e12 100644 (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);
 
index e5766a58a7c5f11286d680a1e8242e62b41593c0..24d402b6e5f0b28e1dac6b7786ca7b8d1e638187 100644 (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,
index a2c8687cf906b829ca201e9cfb97f2d8374df689..578b02ddc0d56d93437b23dfb39f86ee8d3f292d 100644 (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
index 1b7e4c1db1e9a899b848230a3d9f381d07ebc9a0..70f1e8705d836c1d61a83c41dd90bdea57b3a156 100644 (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);