commit 9aa4490263ead62dc545cf0e8b83e0ef77eb7a6e
parent 8b6129312db7b2405f883c4080b835c69a855627
Author: jvoisin <julien.voisin@dustri.org>
Date: Tue, 18 Jul 2023 23:07:05 +0200
Make use of the alloc_size attribute
Diffstat:
2 files changed, 30 insertions(+), 0 deletions(-)
diff --git a/include/fortify-headers.h b/include/fortify-headers.h
@@ -78,6 +78,13 @@
#define __malloc(...)
#endif
+#if __has_attribute (alloc_size)
+#define __alloc_size(...) __attribute__ ((alloc_size (__VA_ARGS__)))
+#else
+#define __alloc_size(...)
+#endif
+
+
#endif /* __has_attribute */
diff --git a/include/stdlib.h b/include/stdlib.h
@@ -37,13 +37,36 @@ extern "C" {
#endif
#undef malloc
+#undef realloc
__malloc(malloc (free, 1))
+__alloc_size(1)
_FORTIFY_FN(malloc) void *malloc(size_t __s)
{
return __orig_malloc(__s);
}
+__alloc_size(2)
+_FORTIFY_FN(realloc) void *realloc(void *__p, size_t __s)
+{
+ return __orig_realloc(__p, __s);
+}
+
+__alloc_size(1, 2)
+_FORTIFY_FN(calloc) void *calloc(size_t __n, size_t __s)
+{
+ return __orig_calloc(__n, __s);
+}
+
+#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
+#undef reallocarray
+__alloc_size (2, 3)
+_FORTIFY_FN(reallocarray) void* reallocarray(void* __p, size_t __n, size_t __s)
+{
+ return __orig_reallocarray(__p, __n, __s);
+}
+#endif
+
/* FIXME clang */
#if (defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) || defined(_BSD_SOURCE)) && !defined(__clang__)
#undef realpath