summaryrefslogtreecommitdiffstats
path: root/src/libcryptobox
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2019-08-12 21:37:19 +0100
committerVsevolod Stakhov <vsevolod@highsecure.ru>2019-08-12 21:37:19 +0100
commitaf366b20a32902e5e3aa222d3f087ff085901a49 (patch)
treec2569b3b582f64dae66f2f10f693ef2276b49a4d /src/libcryptobox
parent80cb19900c3ab36faf92060ea639bccdcda5eaa9 (diff)
downloadrspamd-af366b20a32902e5e3aa222d3f087ff085901a49.tar.gz
rspamd-af366b20a32902e5e3aa222d3f087ff085901a49.zip
[Minor] Fix more alignment and ubsan issues
Diffstat (limited to 'src/libcryptobox')
-rw-r--r--src/libcryptobox/base64/ref.c19
1 files changed, 12 insertions, 7 deletions
diff --git a/src/libcryptobox/base64/ref.c b/src/libcryptobox/base64/ref.c
index 541e4e929..c7cefd761 100644
--- a/src/libcryptobox/base64/ref.c
+++ b/src/libcryptobox/base64/ref.c
@@ -28,13 +28,16 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "config.h"
+#include "libutil/util.h"
extern const uint8_t base64_table_dec[256];
#define INNER_LOOP_64 do { \
+ uint64_t str, res, dec; \
+ bool aligned = rspamd_is_aligned_as(c, str); \
+ bool oaligned = rspamd_is_aligned_as(o, res); \
while (inlen >= 13) { \
- uint64_t str, res, dec; \
- memcpy(&str, c, sizeof(str)); \
+ if (aligned) { str = *(uint64_t *)c; } else {memcpy(&str, c, sizeof(str)); } \
str = GUINT64_TO_BE(str); \
if ((dec = base64_table_dec[str >> 56]) > 63) { \
break; \
@@ -69,7 +72,7 @@ extern const uint8_t base64_table_dec[256];
} \
res |= dec << 16; \
res = GUINT64_FROM_BE(res); \
- *(uint64_t *)o = res; \
+ if (oaligned) {*(uint64_t *)o = res;} else {memcpy(o, &res, sizeof(res));} \
c += 8; \
o += 6; \
outl += 6; \
@@ -78,9 +81,11 @@ extern const uint8_t base64_table_dec[256];
} while (0)
#define INNER_LOOP_32 do { \
+ uint32_t str, res, dec; \
+ bool aligned = rspamd_is_aligned_as(c, str); \
+ bool oaligned = rspamd_is_aligned_as(o, res); \
while (inlen >= 8) { \
- uint32_t str, res, dec; \
- memcpy(&str, c, sizeof(str)); \
+ if (aligned) { str = *(uint32_t *)c; } else {memcpy(&str, c, sizeof(str)); } \
str = GUINT32_TO_BE(str); \
if ((dec = base64_table_dec[str >> 24]) > 63) { \
break; \
@@ -99,7 +104,7 @@ extern const uint8_t base64_table_dec[256];
} \
res |= dec << 8; \
res = GUINT32_FROM_BE(res); \
- *(uint32_t *)o = res; \
+ if (oaligned) {*(uint32_t *)o = res;} else {memcpy(o, &res, sizeof(res));} \
c += 4; \
o += 3; \
outl += 3; \
@@ -150,7 +155,7 @@ repeat:
break;
}
*o++ = carry | (q >> 4);
- carry = q << 4;
+ carry = (uint8_t)(q << 4);
leftover++;
outl++;