diff options
author | Vsevolod Stakhov <vsevolod@rspamd.com> | 2024-03-15 13:18:34 +0000 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@rspamd.com> | 2024-03-15 13:18:34 +0000 |
commit | 1d0ff299f57e94b297d4215fc4429c2aabbc40ba (patch) | |
tree | 025a056b29592a8e0734b1e59fbf0eaf66a2d65a /src/libutil | |
parent | c4ddccba821ed6ec6c54ffdf751e96172a19f6d0 (diff) | |
download | rspamd-1d0ff299f57e94b297d4215fc4429c2aabbc40ba.tar.gz rspamd-1d0ff299f57e94b297d4215fc4429c2aabbc40ba.zip |
[Fix] Do not save multipatterns to FS in certain cases
Diffstat (limited to 'src/libutil')
-rw-r--r-- | src/libutil/multipattern.c | 31 | ||||
-rw-r--r-- | src/libutil/multipattern.h | 9 |
2 files changed, 24 insertions, 16 deletions
diff --git a/src/libutil/multipattern.c b/src/libutil/multipattern.c index 630b1f921..bf3c7ad9a 100644 --- a/src/libutil/multipattern.c +++ b/src/libutil/multipattern.c @@ -1,11 +1,11 @@ -/*- - * Copyright 2016 Vsevolod Stakhov +/* + * Copyright 2024 Vsevolod Stakhov * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -466,7 +466,7 @@ rspamd_multipattern_try_save_hs(struct rspamd_multipattern *mp, #endif gboolean -rspamd_multipattern_compile(struct rspamd_multipattern *mp, GError **err) +rspamd_multipattern_compile(struct rspamd_multipattern *mp, int flags, GError **err) { g_assert(mp != NULL); g_assert(!mp->compiled); @@ -483,7 +483,7 @@ rspamd_multipattern_compile(struct rspamd_multipattern *mp, GError **err) rspamd_cryptobox_hash_update(&mp->hash_state, (void *) &plt, sizeof(plt)); rspamd_cryptobox_hash_final(&mp->hash_state, hash); - if (!rspamd_multipattern_try_load_hs(mp, hash)) { + if ((flags & RSPAMD_MULTIPATTERN_COMPILE_NO_FS) || !rspamd_multipattern_try_load_hs(mp, hash)) { hs_database_t *db = NULL; if (hs_compile_multi((const char *const *) mp->hs_pats->data, @@ -504,18 +504,23 @@ rspamd_multipattern_compile(struct rspamd_multipattern *mp, GError **err) return FALSE; } - if (hs_cache_dir != NULL) { - char fpath[PATH_MAX]; - rspamd_snprintf(fpath, sizeof(fpath), "%s/%*xs.hsmp", hs_cache_dir, - (gint) rspamd_cryptobox_HASHBYTES / 2, hash); - mp->hs_db = rspamd_hyperscan_from_raw_db(db, fpath); + if (!(flags & RSPAMD_MULTIPATTERN_COMPILE_NO_FS)) { + if (hs_cache_dir != NULL) { + char fpath[PATH_MAX]; + rspamd_snprintf(fpath, sizeof(fpath), "%s/%*xs.hsmp", hs_cache_dir, + (gint) rspamd_cryptobox_HASHBYTES / 2, hash); + mp->hs_db = rspamd_hyperscan_from_raw_db(db, fpath); + } + else { + /* Should not happen in the real life */ + mp->hs_db = rspamd_hyperscan_from_raw_db(db, NULL); + } + + rspamd_multipattern_try_save_hs(mp, hash); } else { - /* Should not happen in the real life */ mp->hs_db = rspamd_hyperscan_from_raw_db(db, NULL); } - - rspamd_multipattern_try_save_hs(mp, hash); } for (i = 0; i < MAX_SCRATCH; i++) { diff --git a/src/libutil/multipattern.h b/src/libutil/multipattern.h index 93027661d..15099aaca 100644 --- a/src/libutil/multipattern.h +++ b/src/libutil/multipattern.h @@ -1,11 +1,11 @@ -/*- - * Copyright 2016 Vsevolod Stakhov +/* + * Copyright 2024 Vsevolod Stakhov * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -117,12 +117,15 @@ void rspamd_multipattern_add_pattern(struct rspamd_multipattern *mp, void rspamd_multipattern_add_pattern_len(struct rspamd_multipattern *mp, const gchar *pattern, gsize patlen, gint flags); + +#define RSPAMD_MULTIPATTERN_COMPILE_NO_FS (0x1u << 0u) /** * Compiles multipattern structure * @param mp * @return */ gboolean rspamd_multipattern_compile(struct rspamd_multipattern *mp, + int flags, GError **err); /** |