]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib: Add memcpy() macro that assert-crashes if either parameter is NULL
authorTimo Sirainen <timo.sirainen@open-xchange.com>
Fri, 27 Jan 2023 14:31:28 +0000 (16:31 +0200)
committeraki.tuomi <aki.tuomi@open-xchange.com>
Wed, 1 Feb 2023 11:02:50 +0000 (11:02 +0000)
src/lib/buffer.c
src/lib/lib.h
src/lib/printf-format-fix.c
src/lib/strfuncs.c

index a6d8fef03e68a9d5e8b5a8e7b470d093ee3c12b5..74f4c03b7f98df12156b203352b1970caa33507f 100644 (file)
@@ -6,6 +6,10 @@
 #include "safe-memset.h"
 #include "buffer.h"
 
+/* Disable our memcpy() safety wrapper. This file is very performance sensitive
+   and it's been checked to work correctly with memcpy(). */
+#undef memcpy
+
 struct real_buffer {
        union {
                struct buffer buf;
index 2b1ecde41df6adef70dbe354b7d0676c189993ed..16dc71f58964b7e8b6bb1cf8af4e59199f4e092e 100644 (file)
@@ -66,6 +66,14 @@ typedef void lib_atexit_callback_t(void);
 #define static_assert_array_size(arr, count) \
        static_assert(N_ELEMENTS(arr) == (count), "array/enum size mismatch")
 
+/* Using memcpy() with NULL pointers is undefined behavior. Make sure we don't
+   do that. */
+static inline void *i_memcpy(void *dest, const void *src, size_t n) {
+       i_assert(dest != NULL && src != NULL);
+       return memcpy(dest, src, n);
+}
+#define memcpy(dest, src, n) i_memcpy(dest, src, n)
+
 /* /dev/null opened as O_WRONLY. Opened at lib_init(), so it can be accessed
    also inside chroots. */
 extern int dev_null_fd;
index f72253fef45e4b92c7373fabda20852e60a3f485..d68e4f61595f998acfbe11b7a5e62f803c29b954 100644 (file)
@@ -3,6 +3,10 @@
 #include "lib.h"
 #include "printf-format-fix.h"
 
+/* Disable our memcpy() safety wrapper. This file is very performance sensitive
+   and it's been checked to work correctly with memcpy(). */
+#undef memcpy
+
 static const char *
 fix_format_real(const char *fmt, const char *p, size_t *len_r)
 {
index 8aeecc10a8e0a42af356ee09d5c1a6bfbf5d8ca2..4a4e1d1f5995e16e5f3d10339d02e26c38d1ebbc 100644 (file)
 #include <limits.h>
 #include <ctype.h>
 
+/* Disable our memcpy() safety wrapper. This file is very performance sensitive
+   and it's been checked to work correctly with memcpy(). */
+#undef memcpy
+
 #define STRCONCAT_BUFSIZE 512
 
 enum _str_trim_sides {