<pre style='margin:0'>
Christopher Nielsen (mascguy) pushed a commit to branch master
in repository macports-legacy-support.
</pre>
<p><a href="https://github.com/macports/macports-legacy-support/commit/9850d876561548d244ecbf80ed62b1396cb58600">https://github.com/macports/macports-legacy-support/commit/9850d876561548d244ecbf80ed62b1396cb58600</a></p>
<pre style="white-space: pre; background: #F8F8F8"><span style='display:block; white-space:pre;color:#808000;'>commit 9850d876561548d244ecbf80ed62b1396cb58600
</span>Author: Fred Wright <fw@fwright.net>
AuthorDate: Mon Jun 24 18:16:21 2024 -0700
<span style='display:block; white-space:pre;color:#404040;'> Use proper SDK/lib conditions for stpncpy().
</span><span style='display:block; white-space:pre;color:#404040;'>
</span><span style='display:block; white-space:pre;color:#404040;'> This splits the feature flag for stpncpy() into separate flags for the
</span><span style='display:block; white-space:pre;color:#404040;'> target OS version and the SDK version (the first of many such cases).
</span><span style='display:block; white-space:pre;color:#404040;'> For the library, this just renames the feature flag. For the header,
</span><span style='display:block; white-space:pre;color:#404040;'> it's complicated by the added feature of fixing the possible
</span><span style='display:block; white-space:pre;color:#404040;'> incompatibility between 10.7+ SDKs and old compilers. See the
</span><span style='display:block; white-space:pre;color:#404040;'> comments in string.h.
</span><span style='display:block; white-space:pre;color:#404040;'>
</span><span style='display:block; white-space:pre;color:#404040;'> TESTED:
</span><span style='display:block; white-space:pre;color:#404040;'> Tests pass on all platforms, including mismatched SDK cases.
</span>---
include/MacportsLegacySupport.h | 3 ++-
include/string.h | 26 +++++++++++++++++++-------
src/stpncpy.c | 4 ++--
src/stpncpy_chk.c | 4 ++--
4 files changed, 25 insertions(+), 12 deletions(-)
<span style='display:block; white-space:pre;color:#808080;'>diff --git a/include/MacportsLegacySupport.h b/include/MacportsLegacySupport.h
</span><span style='display:block; white-space:pre;color:#808080;'>index 20d95d8..6b096b7 100644
</span><span style='display:block; white-space:pre;background:#e0e0ff;'>--- a/include/MacportsLegacySupport.h
</span><span style='display:block; white-space:pre;background:#e0e0ff;'>+++ b/include/MacportsLegacySupport.h
</span><span style='display:block; white-space:pre;background:#e0e0e0;'>@@ -137,7 +137,8 @@
</span> #define __MPLS_SDK_CMSG_DATA_FIX__ (__MPLS_SDK_MAJOR < 1060)
/* stpncpy */
<span style='display:block; white-space:pre;background:#ffe0e0;'>-#define __MP_LEGACY_SUPPORT_STPNCPY__ (__MPLS_TARGET_OSVER < 1070)
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+#define __MPLS_SDK_SUPPORT_STPNCPY__ (__MPLS_SDK_MAJOR < 1070)
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+#define __MPLS_LIB_SUPPORT_STPNCPY__ (__MPLS_TARGET_OSVER < 1070)
</span>
/* strnlen */
#define __MP_LEGACY_SUPPORT_STRNLEN__ (__MPLS_TARGET_OSVER < 1070)
<span style='display:block; white-space:pre;color:#808080;'>diff --git a/include/string.h b/include/string.h
</span><span style='display:block; white-space:pre;color:#808080;'>index a9c3a2d..1ce7dbc 100644
</span><span style='display:block; white-space:pre;background:#e0e0ff;'>--- a/include/string.h
</span><span style='display:block; white-space:pre;background:#e0e0ff;'>+++ b/include/string.h
</span><span style='display:block; white-space:pre;background:#e0e0e0;'>@@ -20,16 +20,18 @@
</span> /* MP support header */
#include "MacportsLegacySupport.h"
<span style='display:block; white-space:pre;background:#e0ffe0;'>+/* Do our SDK-related setup */
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+#include <_macports_extras/sdkversion.h>
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span> /* Include the primary system string.h */
#include_next <string.h>
/* stpncpy */
<span style='display:block; white-space:pre;background:#ffe0e0;'>-#if __MP_LEGACY_SUPPORT_STPNCPY__
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+#if __MPLS_SDK_SUPPORT_STPNCPY__
</span> __MP__BEGIN_DECLS
<span style='display:block; white-space:pre;background:#ffe0e0;'>-#undef stpncpy /* In case built with later SDK */
</span> extern char *stpncpy(char *dst, const char *src, size_t n);
__MP__END_DECLS
<span style='display:block; white-space:pre;background:#ffe0e0;'>-#endif /* __MP_LEGACY_SUPPORT_STPNCPY__ */
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+#endif /* __MPLS_SDK_SUPPORT_STPNCPY__ */
</span>
/* strnlen */
#if __MP_LEGACY_SUPPORT_STRNLEN__
<span style='display:block; white-space:pre;background:#e0e0e0;'>@@ -66,15 +68,19 @@ __MP__END_DECLS
</span>
/* stpncpy */
<span style='display:block; white-space:pre;background:#ffe0e0;'>-#if __MP_LEGACY_SUPPORT_STPNCPY__
</span> /*
<span style='display:block; white-space:pre;background:#e0ffe0;'>+ * Ordinarily this would just use the usual SDK conditional. But the
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ * __builtin___stpncpy_chk workaround is useful even when the security
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ * wrapper is supplied by the SDK, so the condition for supplying our own
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ * wrapper is more complicated.
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ *
</span> * Some compilers lack __builtin___stpncpy_chk, requiring a workaround.
* Handling this is complicated by the fact that support was added to
* some compilers prior to the __has_builtin() feature that allows directly
* testing for it. It's possible to work around this based on the compiler
* version, but that's further complicated by the fact that Apple added it
* earlier than the official GCC addition in 4.7. So, in the absence of
<span style='display:block; white-space:pre;background:#ffe0e0;'>- * a positive __has_builtin() result, we need to see whether either the
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ * the availability of __has_builtin(), we need to see whether either the
</span> * GCC version or the Apple GCC version is sufficiently recent.
*
* Apple didn't get around to adding this logic until the 10.9 SDK, even
<span style='display:block; white-space:pre;background:#e0e0e0;'>@@ -90,6 +96,8 @@ __MP__END_DECLS
</span> * in the 10.7+ SDK case, we use a different name for the inline, which
* also avoids a duplicate definition issue.
*/
<span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+/* Create a proper test for the builtin */
</span> #ifdef __has_builtin
#define __HAVE_BUILTIN_STPNCPY_CHK__ __has_builtin(__builtin___stpncpy_chk)
#else
<span style='display:block; white-space:pre;background:#e0e0e0;'>@@ -98,13 +106,17 @@ __MP__END_DECLS
</span> || __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 7))
#endif
<span style='display:block; white-space:pre;background:#e0ffe0;'>+/* Define workaround if needed */
</span> #if !__HAVE_BUILTIN_STPNCPY_CHK__
extern char *__stpncpy_chk(char *dest, const char *src, size_t len,
size_t dstlen);
#define __builtin___stpncpy_chk __stpncpy_chk
<span style='display:block; white-space:pre;background:#e0ffe0;'>+#undef stpncpy
</span> #endif /* !__HAVE_BUILTIN_STPNCPY_CHK__ */
<span style='display:block; white-space:pre;background:#ffe0e0;'>-#undef stpncpy
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+#if __MPLS_SDK_SUPPORT_STPNCPY__ || !__HAVE_BUILTIN_STPNCPY_CHK__
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+/* Define the wrapper, possibly replacing the SDK version */
</span> #define stpncpy(dest, src, len) \
((__darwin_obsz0 (dest) != (size_t) -1) \
? __builtin___stpncpy_chk (dest, src, len, __darwin_obsz (dest)) \
<span style='display:block; white-space:pre;background:#e0e0e0;'>@@ -117,7 +129,7 @@ __mpls_inline_stpncpy_chk (char *__restrict __dest,
</span> return __builtin___stpncpy_chk (__dest, __src, __len, __darwin_obsz(__dest));
}
<span style='display:block; white-space:pre;background:#ffe0e0;'>-#endif /* __MP_LEGACY_SUPPORT_STPNCPY__ */
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+#endif /* __MPLS_SDK_SUPPORT_STPNCPY__ || !__HAVE_BUILTIN_STPNCPY_CHK__ */
</span>
#endif /* _USE_FORTIFY_LEVEL > 0 */
<span style='display:block; white-space:pre;color:#808080;'>diff --git a/src/stpncpy.c b/src/stpncpy.c
</span><span style='display:block; white-space:pre;color:#808080;'>index 469002a..146799a 100644
</span><span style='display:block; white-space:pre;background:#e0e0ff;'>--- a/src/stpncpy.c
</span><span style='display:block; white-space:pre;background:#e0e0ff;'>+++ b/src/stpncpy.c
</span><span style='display:block; white-space:pre;background:#e0e0e0;'>@@ -35,7 +35,7 @@
</span>
/* MP support header */
#include "MacportsLegacySupport.h"
<span style='display:block; white-space:pre;background:#ffe0e0;'>-#if __MP_LEGACY_SUPPORT_STPNCPY__
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+#if __MPLS_LIB_SUPPORT_STPNCPY__
</span>
/* Ensure that we don't use the wrapper macro when defining the function */
#undef _FORTIFY_SOURCE
<span style='display:block; white-space:pre;background:#e0e0e0;'>@@ -67,4 +67,4 @@ stpncpy(char * dst, const char * src, size_t maxlen) {
</span> }
}
<span style='display:block; white-space:pre;background:#ffe0e0;'>-#endif /* __MP_LEGACY_SUPPORT_STPNCPY__ */
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+#endif /* __MPLS_LIB_SUPPORT_STPNCPY__ */
</span><span style='display:block; white-space:pre;color:#808080;'>diff --git a/src/stpncpy_chk.c b/src/stpncpy_chk.c
</span><span style='display:block; white-space:pre;color:#808080;'>index 8f03cc6..d2b0dd4 100644
</span><span style='display:block; white-space:pre;background:#e0e0ff;'>--- a/src/stpncpy_chk.c
</span><span style='display:block; white-space:pre;background:#e0e0ff;'>+++ b/src/stpncpy_chk.c
</span><span style='display:block; white-space:pre;background:#e0e0e0;'>@@ -42,7 +42,7 @@
</span> /* MP support header */
#include "MacportsLegacySupport.h"
/* Note that the support for this mechanism is absent prior to 10.5 */
<span style='display:block; white-space:pre;background:#ffe0e0;'>-#if __MP_LEGACY_SUPPORT_STPNCPY__ && __MPLS_TARGET_OSVER >= 1050
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+#if __MPLS_LIB_SUPPORT_STPNCPY__ && __MPLS_TARGET_OSVER >= 1050
</span>
/* Ensure that we don't create an infinitely recursive check function */
#undef _FORTIFY_SOURCE
<span style='display:block; white-space:pre;background:#e0e0e0;'>@@ -63,4 +63,4 @@ __stpncpy_chk (char *dest, const char *src,
</span> return stpncpy (dest, src, len);
}
<span style='display:block; white-space:pre;background:#ffe0e0;'>-#endif /* __MP_LEGACY_SUPPORT_STPNCPY__ && >= 10.5 */
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+#endif /* __MPLS_LIB_SUPPORT_STPNCPY__ && >= 10.5 */
</span></pre><pre style='margin:0'>
</pre>