commit 2dc5de7: [Minor] Improve errors logging on hyperscan load errors
Vsevolod Stakhov
vsevolod at highsecure.ru
Fri Oct 4 14:56:06 UTC 2019
Author: Vsevolod Stakhov
Date: 2019-10-04 15:51:24 +0100
URL: https://github.com/rspamd/rspamd/commit/2dc5de79ac733dde4c574e970dadf588205d57d5 (HEAD -> master)
[Minor] Improve errors logging on hyperscan load errors
---
src/libserver/re_cache.c | 33 ++++++++++++++++++++++++++-------
1 file changed, 26 insertions(+), 7 deletions(-)
diff --git a/src/libserver/re_cache.c b/src/libserver/re_cache.c
index 971619bb5..9e84e05d3 100644
--- a/src/libserver/re_cache.c
+++ b/src/libserver/re_cache.c
@@ -2113,19 +2113,29 @@ rspamd_re_cache_is_valid_hyperscan_file (struct rspamd_re_cache *cache,
if (memcmp (hash_pos, re_class->hash, sizeof (re_class->hash) - 1) == 0) {
/* Open file and check magic */
+ gssize r;
+
fd = open (path, O_RDONLY);
if (fd == -1) {
- if (!silent) {
+ if (errno != ENOENT || !silent) {
msg_err_re_cache ("cannot open hyperscan cache file %s: %s",
path, strerror (errno));
}
return FALSE;
}
- if (read (fd, magicbuf, sizeof (magicbuf)) != sizeof (magicbuf)) {
- msg_err_re_cache ("cannot read hyperscan cache file %s: %s",
- path, strerror (errno));
+ if ((r = read (fd, magicbuf, sizeof (magicbuf))) != sizeof (magicbuf)) {
+ if (r == -1) {
+ msg_err_re_cache ("cannot read magic from hyperscan "
+ "cache file %s: %s",
+ path, strerror (errno));
+ }
+ else {
+ msg_err_re_cache ("truncated read magic from hyperscan "
+ "cache file %s: %z, %z wanted",
+ path, r, (gsize)sizeof (magicbuf));
+ }
close (fd);
return FALSE;
}
@@ -2147,9 +2157,18 @@ rspamd_re_cache_is_valid_hyperscan_file (struct rspamd_re_cache *cache,
return FALSE;
}
- if (read (fd, &test_plt, sizeof (test_plt)) != sizeof (test_plt)) {
- msg_err_re_cache ("cannot read hyperscan cache file %s: %s",
- path, strerror (errno));
+ if ((r = read (fd, &test_plt, sizeof (test_plt))) != sizeof (test_plt)) {
+ if (r == -1) {
+ msg_err_re_cache ("cannot read platform data from hyperscan "
+ "cache file %s: %s",
+ path, strerror (errno));
+ }
+ else {
+ msg_err_re_cache ("truncated read platform data from hyperscan "
+ "cache file %s: %z, %z wanted",
+ path, r, (gsize)sizeof (magicbuf));
+ }
+
close (fd);
return FALSE;
}
More information about the Commits
mailing list