]> source.dussan.org Git - rspamd.git/commitdiff
[CritFix] Deserialise hyperscan to the page-aligned space to prevent alignment issues
authorVsevolod Stakhov <vsevolod@rspamd.com>
Fri, 11 Nov 2022 20:34:51 +0000 (20:34 +0000)
committerVsevolod Stakhov <vsevolod@rspamd.com>
Fri, 11 Nov 2022 20:37:02 +0000 (20:37 +0000)
Issue: #4329

src/libserver/hyperscan_tools.cxx

index 6187208a9d9d1ba2a003409ee43d7b23cc0cf372..96366067de2d6cce2ea539e46d8ebb8ab3dea1ff 100644 (file)
@@ -306,7 +306,15 @@ auto load_cached_hs_file(const char *fname, std::int64_t offset = 0) -> tl::expe
                                                msg_debug_hyperscan_lambda("multipattern: create new database in %s; %Hz size",
                                                        tmpfile_pattern.data(), unserialized_size);
                                                void *buf;
-                                               posix_memalign(&buf, 16, unserialized_size);
+#ifdef HAVE_GETPAGESIZE
+                                               auto page_size = getpagesize();
+#else
+                                               auto page_size = sysconf(_SC_PAGESIZE);
+#endif
+                                               if (page_size == -1) {
+                                                       page_size = 4096;
+                                               }
+                                               posix_memalign(&buf, page_size, unserialized_size);
                                                if (buf == nullptr) {
                                                        return tl::make_unexpected(error {"Cannot allocate memory", errno, error_category::CRITICAL });
                                                }