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);
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);
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;
"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,
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;
}
if (ret)
- *ret = p;
+ *ret = TAKE_PTR(p);
return 0;
#else
{
/* 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);
{
/* Allocated by empty set. */
- char expect[] = { 0x00, 0x00 };
+ static const char expect[] = { 0x00, 0x00 };
_cleanup_free_ char *nulstr = NULL;
set = set_new(NULL);
{
/* 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);