]> source.dussan.org Git - rspamd.git/commitdiff
[Fix] Do not read out-of-boundary when doing base64 encoding 4942/head
authorVsevolod Stakhov <vsevolod@rspamd.com>
Wed, 24 Apr 2024 13:47:17 +0000 (14:47 +0100)
committerVsevolod Stakhov <vsevolod@rspamd.com>
Wed, 24 Apr 2024 13:47:42 +0000 (14:47 +0100)
src/libutil/str_util.c

index eda3331fad77a053af8e81fe55178fafcb50da9c..f8fff0dca8ef3776dd549eed70b7394b43c0cd45 100644 (file)
@@ -353,7 +353,7 @@ unsigned int rspamd_gstring_icase_hash(gconstpointer key)
 #define ZEROMASK 0x7F7F7F7FU
 #endif
 
-#define HASZERO(x) ~(((((x) &ZEROMASK) + ZEROMASK) | (x)) | ZEROMASK)
+#define HASZERO(x) ~(((((x) & ZEROMASK) + ZEROMASK) | (x)) | ZEROMASK)
 
 gsize rspamd_strlcpy_fast(char *dst, const char *src, gsize siz)
 {
@@ -1303,7 +1303,7 @@ rspamd_encode_base64_common(const unsigned char *in, gsize inlen, int str_len,
        o = out;
        cols = 0;
 
-       while (inlen > 6) {
+       while (inlen >= sizeof(n)) {
                memcpy(&n, in, sizeof(n));
                n = GUINT64_TO_BE(n);
 
@@ -3502,7 +3502,7 @@ rspamd_str_regexp_escape(const char *pattern, gsize slen,
                                        *d++ = '\\';
                                        *d++ = 'x';
                                        *d++ = hexdigests[((t >> 4) & 0xF)];
-                                       *d++ = hexdigests[((t) &0xF)];
+                                       *d++ = hexdigests[((t) & 0xF)];
                                        continue; /* To avoid *d++ = t; */
                                }
                                else {