Revert "main/fortify-headers: upgrade to 2.3.1"

Still have a nasty issue:
https://github.com/jvoisin/fortify-headers/issues/62#issuecomment-2220737276

Revert again til we have this sorted out.

This reverts commit ccebbedc0f.
This commit is contained in:
Natanael Copa 2024-07-10 19:04:15 +02:00
parent f0b7ad9c30
commit 2fcdb47598
4 changed files with 970 additions and 11 deletions

View file

@ -0,0 +1,762 @@
From 1d39f5599ebeb572ac16c3b2e8ad4691463bf6a1 Mon Sep 17 00:00:00 2001
From: Daniel Kolesa <daniel@octaforge.org>
Date: Wed, 26 Oct 2022 00:30:00 +0200
Subject: [PATCH] add initial clang support
---
include/fortify-headers.h | 25 ++++++++++++++++++--
include/poll.h | 7 +++---
include/stdio.h | 38 +++++++++++++++++++++++------
include/stdlib.h | 4 +++-
include/string.h | 33 ++++++++++++++++----------
include/strings.h | 6 +++--
include/sys/select.h | 13 ++++++++--
include/sys/socket.h | 13 ++++++----
include/unistd.h | 30 +++++++++++++----------
include/wchar.h | 50 ++++++++++++++++++++++++++-------------
10 files changed, 158 insertions(+), 61 deletions(-)
diff --git a/include/fortify-headers.h b/include/fortify-headers.h
index 4de5bef..2cf3697 100644
--- a/include/fortify-headers.h
+++ b/include/fortify-headers.h
@@ -1,5 +1,6 @@
/*
* Copyright (C) 2015-2016 Dimitris Papastamos <sin@2f30.org>
+ * Copyright (C) 2022 q66 <q66@chimera-linux.org>
*
* Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted.
@@ -16,9 +17,29 @@
#ifndef _FORTIFY_HEADERS_H
#define _FORTIFY_HEADERS_H
+#ifdef __clang__
+
+/* clang uses overloads; see https://github.com/llvm/llvm-project/issues/53516 */
+#define _FORTIFY_POSN(n) const __attribute__((__pass_object_size__(n)))
+/* we can't use extern inline with overloads without making them external */
+#define _FORTIFY_INLINE static __inline__ \
+ __attribute__((__always_inline__,__artificial__,__overloadable__))
+
+#else /* !__clang__ */
+
+#define _FORTIFY_POSN(n)
+#define _FORTIFY_INLINE extern __inline__ \
+ __attribute__((__always_inline__,__gnu_inline__,__artificial__))
+
+#endif /* __clang__ */
+
+#define _FORTIFY_POS0 _FORTIFY_POSN(0)
+#define _FORTIFY_POS1 _FORTIFY_POSN(1)
+#define _FORTIFY_POS2 _FORTIFY_POSN(2)
+
#define _FORTIFY_STR(s) #s
#define _FORTIFY_ORIG(p,fn) __typeof__(fn) __orig_##fn __asm__(_FORTIFY_STR(p) #fn)
-#define _FORTIFY_FN(fn) _FORTIFY_ORIG(__USER_LABEL_PREFIX__,fn); \
- extern __inline__ __attribute__((__always_inline__,__gnu_inline__,__artificial__))
+#define _FORTIFY_FNB(fn) _FORTIFY_ORIG(__USER_LABEL_PREFIX__,fn)
+#define _FORTIFY_FN(fn) _FORTIFY_FNB(fn); _FORTIFY_INLINE
#endif
diff --git a/include/poll.h b/include/poll.h
index 24691f1..60a7623 100644
--- a/include/poll.h
+++ b/include/poll.h
@@ -1,5 +1,6 @@
/*
* Copyright (C) 2015-2016 Dimitris Papastamos <sin@2f30.org>
+ * Copyright (C) 2022 q66 <q66@chimera-linux.org>
*
* Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted.
@@ -30,7 +31,7 @@ extern "C" {
#undef poll
-_FORTIFY_FN(poll) int poll(struct pollfd *__f, nfds_t __n, int __s)
+_FORTIFY_FN(poll) int poll(struct pollfd * _FORTIFY_POS0 __f, nfds_t __n, int __s)
{
__typeof__(sizeof 0) __b = __builtin_object_size(__f, 0);
@@ -41,8 +42,8 @@ _FORTIFY_FN(poll) int poll(struct pollfd *__f, nfds_t __n, int __s)
#ifdef _GNU_SOURCE
#undef ppoll
-_FORTIFY_FN(ppoll) int ppoll(struct pollfd *__f, nfds_t __n, const struct timespec *__s,
- const sigset_t *__m)
+_FORTIFY_FN(ppoll) int ppoll(struct pollfd * _FORTIFY_POS0 __f, nfds_t __n,
+ const struct timespec *__s, const sigset_t *__m)
{
__typeof__(sizeof 0) __b = __builtin_object_size(__f, 0);
diff --git a/include/stdio.h b/include/stdio.h
index a965184..e50f65f 100644
--- a/include/stdio.h
+++ b/include/stdio.h
@@ -1,5 +1,6 @@
/*
* Copyright (C) 2015-2016 Dimitris Papastamos <sin@2f30.org>
+ * Copyright (C) 2022 q66 <q66@chimera-linux.org>
*
* Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted.
@@ -36,7 +37,7 @@ extern "C" {
#undef snprintf
#undef sprintf
-_FORTIFY_FN(fgets) char *fgets(char *__s, int __n, FILE *__f)
+_FORTIFY_FN(fgets) char *fgets(char * _FORTIFY_POS0 __s, int __n, FILE *__f)
{
size_t __b = __builtin_object_size(__s, 0);
@@ -45,7 +46,8 @@ _FORTIFY_FN(fgets) char *fgets(char *__s, int __n, FILE *__f)
return __orig_fgets(__s, __n, __f);
}
-_FORTIFY_FN(fread) size_t fread(void *__d, size_t __n, size_t __m, FILE *__f)
+_FORTIFY_FN(fread) size_t fread(void * _FORTIFY_POS0 __d, size_t __n,
+ size_t __m, FILE *__f)
{
size_t __b = __builtin_object_size(__d, 0);
@@ -56,7 +58,8 @@ _FORTIFY_FN(fread) size_t fread(void *__d, size_t __n, size_t __m, FILE *__f)
return __orig_fread(__d, __n, __m, __f);
}
-_FORTIFY_FN(fwrite) size_t fwrite(const void *__d, size_t __n, size_t __m, FILE *__f)
+_FORTIFY_FN(fwrite) size_t fwrite(const void * _FORTIFY_POS0 __d, size_t __n,
+ size_t __m, FILE *__f)
{
size_t __b = __builtin_object_size(__d, 0);
@@ -67,8 +70,8 @@ _FORTIFY_FN(fwrite) size_t fwrite(const void *__d, size_t __n, size_t __m, FILE
return __orig_fwrite(__d, __n, __m, __f);
}
-_FORTIFY_FN(vsnprintf) int vsnprintf(char *__s, size_t __n, const char *__f,
- __builtin_va_list __v)
+_FORTIFY_FN(vsnprintf) int vsnprintf(char * _FORTIFY_POS0 __s, size_t __n,
+ const char *__f, __builtin_va_list __v)
{
size_t __b = __builtin_object_size(__s, 0);
@@ -77,7 +80,8 @@ _FORTIFY_FN(vsnprintf) int vsnprintf(char *__s, size_t __n, const char *__f,
return __orig_vsnprintf(__s, __n, __f, __v);
}
-_FORTIFY_FN(vsprintf) int vsprintf(char *__s, const char *__f, __builtin_va_list __v)
+_FORTIFY_FN(vsprintf) int vsprintf(char * _FORTIFY_POS0 __s, const char *__f,
+ __builtin_va_list __v)
{
size_t __b = __builtin_object_size(__s, 0);
int __r;
@@ -92,9 +96,26 @@ _FORTIFY_FN(vsprintf) int vsprintf(char *__s, const char *__f, __builtin_va_list
return __r;
}
-_FORTIFY_FN(snprintf) int snprintf(char *__s, size_t __n, const char *__f, ...)
+#if defined(__has_builtin)
+#if __has_builtin(__builtin_va_arg_pack)
+
+/* clang is missing __builtin_va_arg_pack, so we cannot use these impls
+ * outside of gcc; we then have a few options:
+ *
+ * 1) using va_start/end and implementing these functions as static inline,
+ * with inlining never happening; that means extra symbols with internal
+ * linkage, which is not ideal
+ * 2) using macros; this is incompatible with c++ and since musl does not
+ * have the __chk variants, we'd need to implement a body with intermediate
+ * variables within the macro, which means more non-portable mess
+ * 3) not implementing these under clang, which is what we do for now
+ */
+
+_FORTIFY_FN(snprintf) int snprintf(char *__s, size_t __n,
+ const char *__f, ...)
{
size_t __b = __builtin_object_size(__s, 0);
+ int __r;
if (__n > __b)
__builtin_trap();
@@ -116,6 +137,9 @@ _FORTIFY_FN(sprintf) int sprintf(char *__s, const char *__f, ...)
return __r;
}
+#endif /* __has_builtin(__builtin_va_arg_pack) */
+#endif /* defined(__has_builtin) */
+
#ifdef __cplusplus
}
#endif
diff --git a/include/stdlib.h b/include/stdlib.h
index 11155cf..2b854d0 100644
--- a/include/stdlib.h
+++ b/include/stdlib.h
@@ -1,5 +1,6 @@
/*
* Copyright (C) 2015-2016 Dimitris Papastamos <sin@2f30.org>
+ * Copyright (C) 2022 q66 <q66@chimera-linux.org>
*
* Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted.
@@ -35,7 +36,8 @@ __extension__
extern "C" {
#endif
-#if defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
+/* FIXME clang */
+#if (defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) || defined(_BSD_SOURCE)) && !defined(__clang__)
#undef realpath
_FORTIFY_FN(realpath) char *realpath(const char *__p, char *__r)
{
diff --git a/include/string.h b/include/string.h
index 66c23e1..9d4658c 100644
--- a/include/string.h
+++ b/include/string.h
@@ -1,5 +1,6 @@
/*
* Copyright (C) 2015-2016 Dimitris Papastamos <sin@2f30.org>
+ * Copyright (C) 2022 q66 <q66@chimera-linux.org>
*
* Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted.
@@ -36,7 +37,8 @@ extern "C" {
#undef strncat
#undef strncpy
-_FORTIFY_FN(memcpy) void *memcpy(void *__od, const void *__os, size_t __n)
+_FORTIFY_FN(memcpy) void *memcpy(void * _FORTIFY_POS0 __od,
+ const void * _FORTIFY_POS0 __os, size_t __n)
{
size_t __bd = __builtin_object_size(__od, 0);
size_t __bs = __builtin_object_size(__os, 0);
@@ -53,7 +55,8 @@ _FORTIFY_FN(memcpy) void *memcpy(void *__od, const void *__os, size_t __n)
return __builtin_memcpy(__od, __os, __n);
}
-_FORTIFY_FN(memmove) void *memmove(void *__d, const void *__s, size_t __n)
+_FORTIFY_FN(memmove) void *memmove(void * _FORTIFY_POS0 __d,
+ const void * _FORTIFY_POS0 __s, size_t __n)
{
size_t __bd = __builtin_object_size(__d, 0);
size_t __bs = __builtin_object_size(__s, 0);
@@ -63,7 +66,7 @@ _FORTIFY_FN(memmove) void *memmove(void *__d, const void *__s, size_t __n)
return __orig_memmove(__d, __s, __n);
}
-_FORTIFY_FN(memset) void *memset(void *__d, int __c, size_t __n)
+_FORTIFY_FN(memset) void *memset(void * _FORTIFY_POS0 __d, int __c, size_t __n)
{
size_t __b = __builtin_object_size(__d, 0);
@@ -76,7 +79,7 @@ _FORTIFY_FN(memset) void *memset(void *__d, int __c, size_t __n)
|| defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) \
|| defined(_BSD_SOURCE)
#undef stpcpy
-_FORTIFY_FN(stpcpy) char *stpcpy(char *__d, const char *__s)
+_FORTIFY_FN(stpcpy) char *stpcpy(char * _FORTIFY_POS0 __d, const char *__s)
{
size_t __b = __builtin_object_size(__d, 0);
@@ -86,7 +89,8 @@ _FORTIFY_FN(stpcpy) char *stpcpy(char *__d, const char *__s)
}
#undef stpncpy
-_FORTIFY_FN(stpncpy) char *stpncpy(char *__d, const char *__s, size_t __n)
+_FORTIFY_FN(stpncpy) char *stpncpy(char * _FORTIFY_POS0 __d, const char *__s,
+ size_t __n)
{
size_t __b = __builtin_object_size(__d, 0);
@@ -96,7 +100,7 @@ _FORTIFY_FN(stpncpy) char *stpncpy(char *__d, const char *__s, size_t __n)
}
#endif
-_FORTIFY_FN(strcat) char *strcat(char *__d, const char *__s)
+_FORTIFY_FN(strcat) char *strcat(char * _FORTIFY_POS0 __d, const char *__s)
{
size_t __b = __builtin_object_size(__d, 0);
@@ -105,7 +109,7 @@ _FORTIFY_FN(strcat) char *strcat(char *__d, const char *__s)
return __orig_strcat(__d, __s);
}
-_FORTIFY_FN(strcpy) char *strcpy(char *__d, const char *__s)
+_FORTIFY_FN(strcpy) char *strcpy(char * _FORTIFY_POS0 __d, const char *__s)
{
size_t __b = __builtin_object_size(__d, 0);
@@ -114,7 +118,8 @@ _FORTIFY_FN(strcpy) char *strcpy(char *__d, const char *__s)
return __orig_strcpy(__d, __s);
}
-_FORTIFY_FN(strncat) char *strncat(char *__d, const char *__s, size_t __n)
+_FORTIFY_FN(strncat) char *strncat(char * _FORTIFY_POS0 __d, const char *__s,
+ size_t __n)
{
size_t __b = __builtin_object_size(__d, 0);
size_t __sl, __dl;
@@ -130,7 +135,8 @@ _FORTIFY_FN(strncat) char *strncat(char *__d, const char *__s, size_t __n)
return __orig_strncat(__d, __s, __n);
}
-_FORTIFY_FN(strncpy) char *strncpy(char *__d, const char *__s, size_t __n)
+_FORTIFY_FN(strncpy) char *strncpy(char * _FORTIFY_POS0 __d,
+ const char *__s, size_t __n)
{
size_t __b = __builtin_object_size(__d, 0);
@@ -141,7 +147,8 @@ _FORTIFY_FN(strncpy) char *strncpy(char *__d, const char *__s, size_t __n)
#ifdef _GNU_SOURCE
#undef mempcpy
-_FORTIFY_FN(mempcpy) void *mempcpy(void *__d, const void *__s, size_t __n)
+_FORTIFY_FN(mempcpy) void *mempcpy(void * _FORTIFY_POS0 __d,
+ const void * _FORTIFY_POS0 __s, size_t __n)
{
size_t __bd = __builtin_object_size(__d, 0);
size_t __bs = __builtin_object_size(__s, 0);
@@ -155,7 +162,8 @@ _FORTIFY_FN(mempcpy) void *mempcpy(void *__d, const void *__s, size_t __n)
#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
#undef strlcat
#undef strlcpy
-_FORTIFY_FN(strlcat) size_t strlcat(char *__d, const char *__s, size_t __n)
+_FORTIFY_FN(strlcat) size_t strlcat(char * _FORTIFY_POS0 __d,
+ const char *__s, size_t __n)
{
size_t __b = __builtin_object_size(__d, 0);
@@ -164,7 +172,8 @@ _FORTIFY_FN(strlcat) size_t strlcat(char *__d, const char *__s, size_t __n)
return __orig_strlcat(__d, __s, __n);
}
-_FORTIFY_FN(strlcpy) size_t strlcpy(char *__d, const char *__s, size_t __n)
+_FORTIFY_FN(strlcpy) size_t strlcpy(char * _FORTIFY_POS0 __d,
+ const char *__s, size_t __n)
{
size_t __b = __builtin_object_size(__d, 0);
diff --git a/include/strings.h b/include/strings.h
index a16e1ad..4c7e1c7 100644
--- a/include/strings.h
+++ b/include/strings.h
@@ -1,5 +1,6 @@
/*
* Copyright (C) 2015-2016 Dimitris Papastamos <sin@2f30.org>
+ * Copyright (C) 2022 q66 <q66@chimera-linux.org>
*
* Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted.
@@ -30,7 +31,8 @@ extern "C" {
|| (defined(_XOPEN_SOURCE) && _XOPEN_SOURCE+0 < 700)
#undef bcopy
#undef bzero
-_FORTIFY_FN(bcopy) void bcopy(const void *__s, void *__d, size_t __n)
+_FORTIFY_FN(bcopy) void bcopy(const void * _FORTIFY_POS0 __s,
+ void * _FORTIFY_POS0 __d, size_t __n)
{
size_t __bd = __builtin_object_size(__d, 0);
size_t __bs = __builtin_object_size(__s, 0);
@@ -40,7 +42,7 @@ _FORTIFY_FN(bcopy) void bcopy(const void *__s, void *__d, size_t __n)
return __orig_bcopy(__s, __d, __n);
}
-_FORTIFY_FN(bzero) void bzero(void *__s, size_t __n)
+_FORTIFY_FN(bzero) void bzero(void * _FORTIFY_POS0 __s, size_t __n)
{
size_t __b = __builtin_object_size(__s, 0);
diff --git a/include/sys/select.h b/include/sys/select.h
index bcee8be..527d8e4 100644
--- a/include/sys/select.h
+++ b/include/sys/select.h
@@ -1,5 +1,6 @@
/*
* Copyright (C) 2015-2016 Dimitris Papastamos <sin@2f30.org>
+ * Copyright (C) 2022 q66 <q66@chimera-linux.org>
*
* Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted.
@@ -27,8 +28,14 @@ __extension__
extern "C" {
#endif
+#ifdef __clang__
+#define _FORTIFY_FD_POS0 const __attribute__((__pass_object_size__(0)))
+#else
+#define _FORTIFY_FD_POS0
+#endif
+
static __inline__ __attribute__((__always_inline__,__gnu_inline__,__artificial__))
-void __fortify_FD_CLR(int __f, fd_set *__s)
+void __fortify_FD_CLR(int __f, fd_set * _FORTIFY_FD_POS0 __s)
{
size_t __b = __builtin_object_size(__s, 0);
@@ -38,7 +45,7 @@ void __fortify_FD_CLR(int __f, fd_set *__s)
}
static __inline__ __attribute__((__always_inline__,__gnu_inline__,__artificial__))
-void __fortify_FD_SET(int __f, fd_set *__s)
+void __fortify_FD_SET(int __f, fd_set * _FORTIFY_FD_POS0 __s)
{
size_t __b = __builtin_object_size(__s, 0);
@@ -47,6 +54,8 @@ void __fortify_FD_SET(int __f, fd_set *__s)
FD_SET(__f, __s);
}
+#undef _FORTIFY_FD_POS0
+
#undef FD_CLR
#define FD_CLR(fd, set) __fortify_FD_CLR(fd, set)
#undef FD_SET
diff --git a/include/sys/socket.h b/include/sys/socket.h
index ad6ab2d..02cad5f 100644
--- a/include/sys/socket.h
+++ b/include/sys/socket.h
@@ -1,5 +1,6 @@
/*
* Copyright (C) 2015-2016 Dimitris Papastamos <sin@2f30.org>
+ * Copyright (C) 2022 q66 <q66@chimera-linux.org>
*
* Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted.
@@ -33,7 +34,8 @@ extern "C" {
#undef send
#undef sendto
-_FORTIFY_FN(recv) ssize_t recv(int __f, void *__s, size_t __n, int __fl)
+_FORTIFY_FN(recv) ssize_t recv(int __f, void * _FORTIFY_POS0 __s, size_t __n,
+ int __fl)
{
size_t __b = __builtin_object_size(__s, 0);
@@ -42,7 +44,8 @@ _FORTIFY_FN(recv) ssize_t recv(int __f, void *__s, size_t __n, int __fl)
return __orig_recv(__f, __s, __n, __fl);
}
-_FORTIFY_FN(recvfrom) ssize_t recvfrom(int __f, void *__s, size_t __n, int __fl,
+_FORTIFY_FN(recvfrom) ssize_t recvfrom(int __f, void * _FORTIFY_POS0 __s,
+ size_t __n, int __fl,
struct sockaddr *__a, socklen_t *__l)
{
size_t __b = __builtin_object_size(__s, 0);
@@ -52,7 +55,8 @@ _FORTIFY_FN(recvfrom) ssize_t recvfrom(int __f, void *__s, size_t __n, int __fl,
return __orig_recvfrom(__f, __s, __n, __fl, __a, __l);
}
-_FORTIFY_FN(send) ssize_t send(int __f, const void *__s, size_t __n, int __fl)
+_FORTIFY_FN(send) ssize_t send(int __f, const void * _FORTIFY_POS0 __s,
+ size_t __n, int __fl)
{
size_t __b = __builtin_object_size(__s, 0);
@@ -61,7 +65,8 @@ _FORTIFY_FN(send) ssize_t send(int __f, const void *__s, size_t __n, int __fl)
return __orig_send(__f, __s, __n, __fl);
}
-_FORTIFY_FN(sendto) ssize_t sendto(int __f, const void *__s, size_t __n, int __fl,
+_FORTIFY_FN(sendto) ssize_t sendto(int __f, const void * _FORTIFY_POS0 __s,
+ size_t __n, int __fl,
const struct sockaddr *__a, socklen_t __l)
{
size_t __b = __builtin_object_size(__s, 0);
diff --git a/include/unistd.h b/include/unistd.h
index 09980ba..9f8a187 100644
--- a/include/unistd.h
+++ b/include/unistd.h
@@ -1,5 +1,6 @@
/*
* Copyright (C) 2015-2016 Dimitris Papastamos <sin@2f30.org>
+ * Copyright (C) 2022 q66 <q66@chimera-linux.org>
*
* Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted.
@@ -40,7 +41,7 @@ extern "C" {
#undef ttyname_r
#undef write
-_FORTIFY_FN(confstr) size_t confstr(int __n, char *__s, size_t __l)
+_FORTIFY_FN(confstr) size_t confstr(int __n, char * _FORTIFY_POS0 __s, size_t __l)
{
size_t __b = __builtin_object_size(__s, 0);
size_t __r = __orig_confstr(__n, __s, __b > __l ? __l : __b);
@@ -50,7 +51,7 @@ _FORTIFY_FN(confstr) size_t confstr(int __n, char *__s, size_t __l)
return __r;
}
-_FORTIFY_FN(getcwd) char *getcwd(char *__s, size_t __l)
+_FORTIFY_FN(getcwd) char *getcwd(char * _FORTIFY_POS0 __s, size_t __l)
{
size_t __b = __builtin_object_size(__s, 0);
@@ -61,7 +62,7 @@ _FORTIFY_FN(getcwd) char *getcwd(char *__s, size_t __l)
#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
#undef getdomainname
-_FORTIFY_FN(getdomainname) int getdomainname(char *__s, size_t __l)
+_FORTIFY_FN(getdomainname) int getdomainname(char * _FORTIFY_POS0 __s, size_t __l)
{
size_t __b = __builtin_object_size(__s, 0);
@@ -71,7 +72,7 @@ _FORTIFY_FN(getdomainname) int getdomainname(char *__s, size_t __l)
}
#endif
-_FORTIFY_FN(getgroups) int getgroups(int __l, gid_t *__s)
+_FORTIFY_FN(getgroups) int getgroups(int __l, gid_t * _FORTIFY_POS0 __s)
{
size_t __b = __builtin_object_size(__s, 0);
@@ -80,7 +81,7 @@ _FORTIFY_FN(getgroups) int getgroups(int __l, gid_t *__s)
return __orig_getgroups(__l, __s);
}
-_FORTIFY_FN(gethostname) int gethostname(char *__s, size_t __l)
+_FORTIFY_FN(gethostname) int gethostname(char * _FORTIFY_POS0 __s, size_t __l)
{
size_t __b = __builtin_object_size(__s, 0);
@@ -89,7 +90,7 @@ _FORTIFY_FN(gethostname) int gethostname(char *__s, size_t __l)
return __orig_gethostname(__s, __l);
}
-_FORTIFY_FN(getlogin_r) int getlogin_r(char *__s, size_t __l)
+_FORTIFY_FN(getlogin_r) int getlogin_r(char * _FORTIFY_POS0 __s, size_t __l)
{
size_t __b = __builtin_object_size(__s, 0);
@@ -98,7 +99,8 @@ _FORTIFY_FN(getlogin_r) int getlogin_r(char *__s, size_t __l)
return __orig_getlogin_r(__s, __l);
}
-_FORTIFY_FN(pread) ssize_t pread(int __f, void *__s, size_t __n, off_t __o)
+_FORTIFY_FN(pread) ssize_t pread(int __f, void * _FORTIFY_POS0 __s,
+ size_t __n, off_t __o)
{
size_t __b = __builtin_object_size(__s, 0);
@@ -107,7 +109,7 @@ _FORTIFY_FN(pread) ssize_t pread(int __f, void *__s, size_t __n, off_t __o)
return __orig_pread(__f, __s, __n, __o);
}
-_FORTIFY_FN(read) ssize_t read(int __f, void *__s, size_t __n)
+_FORTIFY_FN(read) ssize_t read(int __f, void * _FORTIFY_POS0 __s, size_t __n)
{
size_t __b = __builtin_object_size(__s, 0);
@@ -116,7 +118,8 @@ _FORTIFY_FN(read) ssize_t read(int __f, void *__s, size_t __n)
return __orig_read(__f, __s, __n);
}
-_FORTIFY_FN(readlink) ssize_t readlink(const char *__p, char *__s, size_t __n)
+_FORTIFY_FN(readlink) ssize_t readlink(const char *__p,
+ char * _FORTIFY_POS0 __s, size_t __n)
{
size_t __b = __builtin_object_size(__s, 0);
@@ -125,7 +128,8 @@ _FORTIFY_FN(readlink) ssize_t readlink(const char *__p, char *__s, size_t __n)
return __orig_readlink(__p, __s, __n);
}
-_FORTIFY_FN(readlinkat) ssize_t readlinkat(int __f, const char *__p, char *__s, size_t __n)
+_FORTIFY_FN(readlinkat) ssize_t readlinkat(int __f, const char *__p,
+ char * _FORTIFY_POS0 __s, size_t __n)
{
size_t __b = __builtin_object_size(__s, 0);
@@ -134,7 +138,8 @@ _FORTIFY_FN(readlinkat) ssize_t readlinkat(int __f, const char *__p, char *__s,
return __orig_readlinkat(__f, __p, __s, __n);
}
-_FORTIFY_FN(ttyname_r) int ttyname_r(int __f, char *__s, size_t __n)
+_FORTIFY_FN(ttyname_r) int ttyname_r(int __f, char * _FORTIFY_POS0 __s,
+ size_t __n)
{
size_t __b = __builtin_object_size(__s, 0);
@@ -143,7 +148,8 @@ _FORTIFY_FN(ttyname_r) int ttyname_r(int __f, char *__s, size_t __n)
return __orig_ttyname_r(__f, __s, __n);
}
-_FORTIFY_FN(write) ssize_t write(int __f, const void *__s, size_t __n)
+_FORTIFY_FN(write) ssize_t write(int __f, const void * _FORTIFY_POS0 __s,
+ size_t __n)
{
size_t __b = __builtin_object_size(__s, 0);
diff --git a/include/wchar.h b/include/wchar.h
index c5d0e5d..41423a8 100644
--- a/include/wchar.h
+++ b/include/wchar.h
@@ -1,5 +1,6 @@
/*
* Copyright (C) 2015-2017 Dimitris Papastamos <sin@2f30.org>
+ * Copyright (C) 2022 q66 <q66@chimera-linux.org>
*
* Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted.
@@ -55,7 +56,8 @@ extern "C" {
#undef wmemmove
#undef wmemset
-_FORTIFY_FN(fgetws) wchar_t *fgetws(wchar_t *__s, int __n, FILE *__f)
+_FORTIFY_FN(fgetws) wchar_t *fgetws(wchar_t * _FORTIFY_POS0 __s,
+ int __n, FILE *__f)
{
size_t __b = __builtin_object_size(__s, 0);
@@ -67,7 +69,8 @@ _FORTIFY_FN(fgetws) wchar_t *fgetws(wchar_t *__s, int __n, FILE *__f)
#if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) \
|| defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
#undef mbsnrtowcs
-_FORTIFY_FN(mbsnrtowcs) size_t mbsnrtowcs(wchar_t *__d, const char **__s, size_t __n,
+_FORTIFY_FN(mbsnrtowcs) size_t mbsnrtowcs(wchar_t * _FORTIFY_POS0 __d,
+ const char **__s, size_t __n,
size_t __wn, mbstate_t *__st)
{
size_t __b = __builtin_object_size(__d, 0);
@@ -87,7 +90,8 @@ _FORTIFY_FN(mbsnrtowcs) size_t mbsnrtowcs(wchar_t *__d, const char **__s, size_t
}
#endif
-_FORTIFY_FN(mbsrtowcs) size_t mbsrtowcs(wchar_t *__d, const char **__s, size_t __wn,
+_FORTIFY_FN(mbsrtowcs) size_t mbsrtowcs(wchar_t * _FORTIFY_POS0 __d,
+ const char **__s, size_t __wn,
mbstate_t *__st)
{
size_t __b = __builtin_object_size(__d, 0);
@@ -100,7 +104,8 @@ _FORTIFY_FN(mbsrtowcs) size_t mbsrtowcs(wchar_t *__d, const char **__s, size_t _
return __r;
}
-_FORTIFY_FN(mbstowcs) size_t mbstowcs(wchar_t *__ws, const char *__s, size_t __wn)
+_FORTIFY_FN(mbstowcs) size_t mbstowcs(wchar_t * _FORTIFY_POS0 __ws,
+ const char *__s, size_t __wn)
{
size_t __b = __builtin_object_size(__ws, 0);
@@ -109,7 +114,9 @@ _FORTIFY_FN(mbstowcs) size_t mbstowcs(wchar_t *__ws, const char *__s, size_t __w
return __orig_mbstowcs(__ws, __s, __wn);
}
-_FORTIFY_FN(wcrtomb) size_t wcrtomb(char *__s, wchar_t __w, mbstate_t *__st)
+/* FIXME clang */
+#ifndef __clang__
+_FORTIFY_FN(wcrtomb) size_t wcrtomb(char * __s, wchar_t __w, mbstate_t *__st)
{
if (__s && MB_LEN_MAX > __builtin_object_size(__s, 2)) {
char __buf[MB_LEN_MAX];
@@ -125,8 +132,10 @@ _FORTIFY_FN(wcrtomb) size_t wcrtomb(char *__s, wchar_t __w, mbstate_t *__st)
}
return __orig_wcrtomb(__s, __w, __st);
}
+#endif
-_FORTIFY_FN(wcscat) wchar_t *wcscat(wchar_t *__d, const wchar_t *__s)
+_FORTIFY_FN(wcscat) wchar_t *wcscat(wchar_t * _FORTIFY_POS0 __d,
+ const wchar_t *__s)
{
size_t __b = __builtin_object_size(__d, 0);
@@ -135,7 +144,8 @@ _FORTIFY_FN(wcscat) wchar_t *wcscat(wchar_t *__d, const wchar_t *__s)
return __orig_wcscat(__d, __s);
}
-_FORTIFY_FN(wcscpy) wchar_t *wcscpy(wchar_t *__d, const wchar_t *__s)
+_FORTIFY_FN(wcscpy) wchar_t *wcscpy(wchar_t * _FORTIFY_POS0 __d,
+ const wchar_t *__s)
{
size_t __b = __builtin_object_size(__d, 0);
@@ -144,7 +154,8 @@ _FORTIFY_FN(wcscpy) wchar_t *wcscpy(wchar_t *__d, const wchar_t *__s)
return __orig_wcscpy(__d, __s);
}
-_FORTIFY_FN(wcsncat) wchar_t *wcsncat(wchar_t *__d, const wchar_t *__s, size_t __n)
+_FORTIFY_FN(wcsncat) wchar_t *wcsncat(wchar_t * _FORTIFY_POS0 __d,
+ const wchar_t *__s, size_t __n)
{
size_t __b = __builtin_object_size(__d, 0);
size_t __sl, __dl;
@@ -160,7 +171,8 @@ _FORTIFY_FN(wcsncat) wchar_t *wcsncat(wchar_t *__d, const wchar_t *__s, size_t _
return __orig_wcsncat(__d, __s, __n);
}
-_FORTIFY_FN(wcsncpy) wchar_t *wcsncpy(wchar_t *__d, const wchar_t *__s, size_t __n)
+_FORTIFY_FN(wcsncpy) wchar_t *wcsncpy(wchar_t * _FORTIFY_POS0 __d,
+ const wchar_t *__s, size_t __n)
{
size_t __b = __builtin_object_size(__d, 0);
@@ -172,7 +184,8 @@ _FORTIFY_FN(wcsncpy) wchar_t *wcsncpy(wchar_t *__d, const wchar_t *__s, size_t _
#if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) \
|| defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
#undef wcsnrtombs
-_FORTIFY_FN(wcsnrtombs) size_t wcsnrtombs(char *__d, const wchar_t **__s, size_t __wn,
+_FORTIFY_FN(wcsnrtombs) size_t wcsnrtombs(char * _FORTIFY_POS0 __d,
+ const wchar_t **__s, size_t __wn,
size_t __n, mbstate_t *__st)
{
size_t __b = __builtin_object_size(__d, 0);
@@ -192,7 +205,8 @@ _FORTIFY_FN(wcsnrtombs) size_t wcsnrtombs(char *__d, const wchar_t **__s, size_t
}
#endif
-_FORTIFY_FN(wcsrtombs) size_t wcsrtombs(char *__d, const wchar_t **__s, size_t __n,
+_FORTIFY_FN(wcsrtombs) size_t wcsrtombs(char * _FORTIFY_POS0 __d,
+ const wchar_t **__s, size_t __n,
mbstate_t *__st)
{
size_t __b = __builtin_object_size(__d, 0);
@@ -204,7 +218,8 @@ _FORTIFY_FN(wcsrtombs) size_t wcsrtombs(char *__d, const wchar_t **__s, size_t _
return __r;
}
-_FORTIFY_FN(wcstombs) size_t wcstombs(char *__s, const wchar_t *__ws, size_t __n)
+_FORTIFY_FN(wcstombs) size_t wcstombs(char * _FORTIFY_POS0 __s,
+ const wchar_t *__ws, size_t __n)
{
size_t __b = __builtin_object_size(__s, 0);
@@ -213,7 +228,7 @@ _FORTIFY_FN(wcstombs) size_t wcstombs(char *__s, const wchar_t *__ws, size_t __n
return __orig_wcstombs(__s, __ws, __n);
}
-_FORTIFY_FN(wctomb) int wctomb(char *__s, wchar_t __w)
+_FORTIFY_FN(wctomb) int wctomb(char * _FORTIFY_POS0 __s, wchar_t __w)
{
size_t __b = __builtin_object_size(__s, 0);
@@ -222,7 +237,8 @@ _FORTIFY_FN(wctomb) int wctomb(char *__s, wchar_t __w)
return __orig_wctomb(__s, __w);
}
-_FORTIFY_FN(wmemcpy) wchar_t *wmemcpy(wchar_t *__d, const wchar_t *__s, size_t __n)
+_FORTIFY_FN(wmemcpy) wchar_t *wmemcpy(wchar_t * _FORTIFY_POS0 __d,
+ const wchar_t *__s, size_t __n)
{
size_t __b = __builtin_object_size(__d, 0);
@@ -231,7 +247,8 @@ _FORTIFY_FN(wmemcpy) wchar_t *wmemcpy(wchar_t *__d, const wchar_t *__s, size_t _
return __orig_wmemcpy(__d, __s, __n);
}
-_FORTIFY_FN(wmemmove) wchar_t *wmemmove(wchar_t *__d, const wchar_t *__s, size_t __n)
+_FORTIFY_FN(wmemmove) wchar_t *wmemmove(wchar_t * _FORTIFY_POS0 __d,
+ const wchar_t *__s, size_t __n)
{
size_t __b = __builtin_object_size(__d, 0);
@@ -240,7 +257,8 @@ _FORTIFY_FN(wmemmove) wchar_t *wmemmove(wchar_t *__d, const wchar_t *__s, size_t
return __orig_wmemmove(__d, __s, __n);
}
-_FORTIFY_FN(wmemset) wchar_t *wmemset(wchar_t *__s, wchar_t __c, size_t __n)
+_FORTIFY_FN(wmemset) wchar_t *wmemset(wchar_t * _FORTIFY_POS0 __s,
+ wchar_t __c, size_t __n)
{
size_t __b = __builtin_object_size(__s, 0);

View file

@ -0,0 +1,144 @@
From 85afbd3d5a11b48a2d0fa77bcefab20c2f9f5292 Mon Sep 17 00:00:00 2001
From: Daniel Kolesa <daniel@octaforge.org>
Date: Tue, 1 Nov 2022 01:03:48 +0100
Subject: [PATCH] avoid __extension__ with clang
It seems useless and triggers 'error: expected external declaration'
---
include/poll.h | 2 +-
include/stdio.h | 2 +-
include/stdlib.h | 4 ++--
include/string.h | 2 +-
include/sys/select.h | 2 +-
include/sys/socket.h | 2 +-
include/unistd.h | 2 +-
include/wchar.h | 8 ++++----
8 files changed, 12 insertions(+), 12 deletions(-)
diff --git a/include/poll.h b/include/poll.h
index 60a7623..b8d5c0b 100644
--- a/include/poll.h
+++ b/include/poll.h
@@ -17,7 +17,7 @@
#ifndef _FORTIFY_POLL_H
#define _FORTIFY_POLL_H
-#ifndef __cplusplus
+#if !defined(__cplusplus) && !defined(__clang__)
__extension__
#endif
#include_next <poll.h>
diff --git a/include/stdio.h b/include/stdio.h
index e50f65f..a5aaa8f 100644
--- a/include/stdio.h
+++ b/include/stdio.h
@@ -17,7 +17,7 @@
#ifndef _FORTIFY_STDIO_H
#define _FORTIFY_STDIO_H
-#ifndef __cplusplus
+#if !defined(__cplusplus) && !defined(__clang__)
__extension__
#endif
#include_next <stdio.h>
diff --git a/include/stdlib.h b/include/stdlib.h
index 2b854d0..c43a835 100644
--- a/include/stdlib.h
+++ b/include/stdlib.h
@@ -17,14 +17,14 @@
#ifndef _FORTIFY_STDLIB_H
#define _FORTIFY_STDLIB_H
-#ifndef __cplusplus
+#if !defined(__cplusplus) && !defined(__clang__)
__extension__
#endif
#include_next <stdlib.h>
#if defined(_FORTIFY_SOURCE) && _FORTIFY_SOURCE > 0 && defined(__OPTIMIZE__) && __OPTIMIZE__ > 0
#if defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
-#ifndef __cplusplus
+#if !defined(__cplusplus) && !defined(__clang__)
__extension__
#endif
#include_next <limits.h>
diff --git a/include/string.h b/include/string.h
index 9d4658c..834d262 100644
--- a/include/string.h
+++ b/include/string.h
@@ -17,7 +17,7 @@
#ifndef _FORTIFY_STRING_H
#define _FORTIFY_STRING_H
-#ifndef __cplusplus
+#if !defined(__cplusplus) && !defined(__clang__)
__extension__
#endif
#include_next <string.h>
diff --git a/include/sys/select.h b/include/sys/select.h
index 527d8e4..75c4829 100644
--- a/include/sys/select.h
+++ b/include/sys/select.h
@@ -17,7 +17,7 @@
#ifndef _FORTIFY_SYS_SELECT_H
#define _FORTIFY_SYS_SELECT_H
-#ifndef __cplusplus
+#if !defined(__cplusplus) && !defined(__clang__)
__extension__
#endif
#include_next <sys/select.h>
diff --git a/include/sys/socket.h b/include/sys/socket.h
index 02cad5f..5a1821c 100644
--- a/include/sys/socket.h
+++ b/include/sys/socket.h
@@ -17,7 +17,7 @@
#ifndef _FORTIFY_SYS_SOCKET_H
#define _FORTIFY_SYS_SOCKET_H
-#ifndef __cplusplus
+#if !defined(__cplusplus) && !defined(__clang__)
__extension__
#endif
#include_next <sys/socket.h>
diff --git a/include/unistd.h b/include/unistd.h
index 9f8a187..d36dfc4 100644
--- a/include/unistd.h
+++ b/include/unistd.h
@@ -17,7 +17,7 @@
#ifndef _FORTIFY_UNISTD_H
#define _FORTIFY_UNISTD_H
-#ifndef __cplusplus
+#if !defined(__cplusplus) && !defined(__clang__)
__extension__
#endif
#include_next <unistd.h>
diff --git a/include/wchar.h b/include/wchar.h
index 41423a8..e359452 100644
--- a/include/wchar.h
+++ b/include/wchar.h
@@ -17,19 +17,19 @@
#ifndef _FORTIFY_WCHAR_H
#define _FORTIFY_WCHAR_H
-#ifndef __cplusplus
+#if !defined(__cplusplus) && !defined(__clang__)
__extension__
#endif
#include_next <limits.h>
-#ifndef __cplusplus
+#if !defined(__cplusplus) && !defined(__clang__)
__extension__
#endif
#include_next <stdlib.h>
-#ifndef __cplusplus
+#if !defined(__cplusplus) && !defined(__clang__)
__extension__
#endif
#include_next <string.h>
-#ifndef __cplusplus
+#if !defined(__cplusplus) && !defined(__clang__)
__extension__
#endif
#include_next <wchar.h>

View file

@ -0,0 +1,53 @@
From 6ee1b1498e409b5494a6bbedfd143105380edbac Mon Sep 17 00:00:00 2001
From: Laurent Bercot <ska-devel@skarnet.org>
Date: Tue, 16 Feb 2021 18:46:10 +0100
Subject: [PATCH] Disable wrapping of ppoll
The fortify-headers/poll.h definitions incorrectly forward the ppoll()
function: on some archs (armv7 for instance), musl renames the symbol to
accommodate for time_t size, and fortify-headers misses that.
This causes ppoll() to break on all time32 systems. This commit axes
the ppoll() redefinition. Fortifying ppoll() is of very little benefit
anyway.
---
README | 1 -
include/poll.h | 13 -------------
2 files changed, 14 deletions(-)
diff --git a/README b/README
index 7e9c111..f620a47 100644
--- a/README
+++ b/README
@@ -67,7 +67,6 @@ memmove
mempcpy
memset
poll
-ppoll
pread
read
readlink
diff --git a/include/poll.h b/include/poll.h
index b8d5c0b..04f28cb 100644
--- a/include/poll.h
+++ b/include/poll.h
@@ -40,19 +40,6 @@ _FORTIFY_FN(poll) int poll(struct pollfd * _FORTIFY_POS0 __f, nfds_t __n, int __
return __orig_poll(__f, __n, __s);
}
-#ifdef _GNU_SOURCE
-#undef ppoll
-_FORTIFY_FN(ppoll) int ppoll(struct pollfd * _FORTIFY_POS0 __f, nfds_t __n,
- const struct timespec *__s, const sigset_t *__m)
-{
- __typeof__(sizeof 0) __b = __builtin_object_size(__f, 0);
-
- if (__n > __b / sizeof(struct pollfd))
- __builtin_trap();
- return __orig_ppoll(__f, __n, __s, __m);
-}
-#endif
-
#ifdef __cplusplus
}
#endif

View file

@ -1,17 +1,17 @@
# Contributor: Timo Teräs <timo.teras@iki.fi>
# Maintainer: Timo Teräs <timo.teras@iki.fi>
pkgname=fortify-headers
pkgver=2.3.1
pkgrel=2
pkgver=1.1
pkgrel=5
pkgdesc="standalone fortify source implementation"
url="https://github.com/jvoisin/fortify-headers"
url="http://git.2f30.org/fortify-headers/"
arch="noarch"
options="!check" # No test suite.
license="0BSD"
source="$pkgname-$pkgver.tar.gz::https://github.com/jvoisin/fortify-headers/archive/refs/tags/$pkgver.tar.gz
$pkgname-vsnprintf.patch::https://github.com/jvoisin/fortify-headers/commit/6f5423255b6d78b0d6979e6319642ae530f3e2b7.patch
$pkgname-snprintf.patch::https://github.com/jvoisin/fortify-headers/commit/9014b0266147dbb74d5d9e6e2c24ae9d21ad7e07.patch
$pkgname-strncpy.patch::https://github.com/jvoisin/fortify-headers/commit/c4d9299abf7f6b941493fc487d2ccbb47d756479.patch
source="http://dl.2f30.org/releases/fortify-headers-$pkgver.tar.gz
0001-add-initial-clang-support.patch
0002-avoid-__extension__-with-clang.patch
0003-Disable-wrapping-of-ppoll.patch
"
package() {
@ -19,8 +19,8 @@ package() {
}
sha512sums="
c9ad5bd58e4378f18fdeb8ec4730570e38ca2369c14e249ec60afcfff2b7195bd6121641e01dc7be7a122f5dd0992859084a54a40d2c1d80389eb8a42b577557 fortify-headers-2.3.1.tar.gz
82adc8bade6be58cf4cb5ea1ba38829030d9d3cc569d4143c286e34c383b3814574bca9b8528c955d7c7479fab5bcfb98e97223c6648ff6cd95e9553d5cda304 fortify-headers-vsnprintf.patch
add8b3501703c7d6af12450e13778e4bc8479106de080f3a1c5d5a1780ce82b2ccc743722f39c277c6779e213145857c73a3a3262666924c1ad74b59b151598e fortify-headers-snprintf.patch
f2f5fb9e8c42528ad6815cb3cc8377ad72108c7a238cf3a01fbd4d6366469e3b7e6236d6126ee5434518e93c4add8263a932884d1814c0ba9d93a9a727f35144 fortify-headers-strncpy.patch
a39d6e7c002bf91085f712aa46bc3f53ff934cc963694a229fa82d84ff4a7556105212a84a231ab5367c01c6a1e385172173f1f4a34d5eb4d2d9c58472c23dd0 fortify-headers-1.1.tar.gz
eeeb4ca86cd59eb0ec3cfab004c9b7b4a4fd9a6c5db8e97d4fd5fda959249553a0a020653cd87e833799bbd2aba2ae628a9e8805272146bd7f895ba6624cdeef 0001-add-initial-clang-support.patch
4737e6de59ab65e4c8eb285fb716932558c6238f6f0e303eeebfacb106306959fa567d1dc23e2364b1561a06f0013e2fa2e7e7d0ab7dd8c13095a7192d451e89 0002-avoid-__extension__-with-clang.patch
90d9dfee98b2fb8536f20588ce6017a0d69d1ad12033515f140e3a201eeb0b61be72796dddfb8fc0ccb0fccce202c9206c9db159e3f7ef4c4de4474793c01333 0003-Disable-wrapping-of-ppoll.patch
"