Skip to content
Snippets Groups Projects
Commit 46a30685 authored by Fred Wright's avatar Fred Wright Committed by Christopher Nielsen
Browse files

realpath: Fix 10.6 non-POSIX version.

This adds our allocating wrapper to the 10.6 non-POSIX case, which
returns an unsafe buffer pointer when supplied with a nonexistent path
and no buffer.  Providing our own malloc()ed buffer avoids the
problem.  This only affects 32-bit builds, since 64-bit non-POSIX is
nonexistent.

The original flag is renamed in the process, with the original name
now reflecting the combined need for the wrapper.

Some whitespace cleanup is also applied to the other composite flag
definitions.

Updates README to reflect the fix.

TESTED:
Tests pass on all platforms, including newly added test case (next
commit).
parent 301c8575
Branches
No related tags found
No related merge requests found
...@@ -75,11 +75,18 @@ Wrapped headers and replaced functions are: ...@@ -75,11 +75,18 @@ Wrapped headers and replaced functions are:
<td>OSX10.6, OSX10.12 (open_memstream)</td> <td>OSX10.6, OSX10.12 (open_memstream)</td>
</tr> </tr>
<tr> <tr>
<td rowspan="2"><code>stdlib.h</code></td> <td rowspan="4"><code>stdlib.h</code></td>
<td>Adds <code>posix_memalign</code> functional replacement, and wraps <code>realpath</code> <td>Adds <code>posix_memalign</code> functional replacement</td>
to accept a <code>NULL</code> buffer argument</td>
<td>OSX10.5</td> <td>OSX10.5</td>
</tr> </tr>
<tr>
<td>Wraps <code>realpath</code> to accept a <code>NULL</code> buffer argument</td>
<td>OSX10.5</td>
</tr>
<tr>
<td>Fixes non-POSIX <code>realpath</code> in 10.6</td>
<td>OSX10.6</td>
</tr>
<tr> <tr>
<td>Adds <code>arc4random_uniform</code> and <code>arc4random_buf</code> functions</td> <td>Adds <code>arc4random_uniform</code> and <code>arc4random_buf</code> functions</td>
<td>OSX10.6</td> <td>OSX10.6</td>
......
...@@ -230,7 +230,13 @@ ...@@ -230,7 +230,13 @@
/* The addition uses an #ifndef, so no feature flag is necessary */ /* The addition uses an #ifndef, so no feature flag is necessary */
/* realpath() on < 10.6 does not support modern NULL buffer usage */ /* realpath() on < 10.6 does not support modern NULL buffer usage */
#define __MPLS_LIB_SUPPORT_REALPATH_WRAP__ (__MPLS_TARGET_OSVER < 1060) #define __MPLS_LIB_SUPPORT_REALPATH_ALLOC__ (__MPLS_TARGET_OSVER < 1060)
/* Also, 10.6 non-POSIX realpath() (32-bit only) with a nonexistent path and
* a NULL buffer returns an unsafe pointer to an internal buffer. */
#define __MPLS_LIB_SUPPORT_REALPATH_NONEX_FIX__ (__MPLS_TARGET_OSVER >= 1060 \
&& __MPLS_TARGET_OSVER < 1070 \
&& !__MPLS_64BIT)
/* fsetattrlistat, fgetattrlistat */ /* fsetattrlistat, fgetattrlistat */
#define __MPLS_SDK_SUPPORT_FSETATTRLIST__ (__MPLS_SDK_MAJOR < 1060) #define __MPLS_SDK_SUPPORT_FSETATTRLIST__ (__MPLS_SDK_MAJOR < 1060)
...@@ -316,10 +322,18 @@ ...@@ -316,10 +322,18 @@
#define __MPLS_LIB_SUPPORT_PTHREAD_SETNAME_NP__ (__MPLS_TARGET_OSVER < 1060) #define __MPLS_LIB_SUPPORT_PTHREAD_SETNAME_NP__ (__MPLS_TARGET_OSVER < 1060)
/* Compound macros, bundling functionality needed by multiple single features. */ /* Compound macros, bundling functionality needed by multiple single features. */
#define __MPLS_SDK_NEED_ATCALL_MACROS__ (__MPLS_SDK_SUPPORT_ATCALLS__ || __MPLS_SDK_SUPPORT_SETATTRLISTAT__) #define __MPLS_SDK_NEED_ATCALL_MACROS__ (__MPLS_SDK_SUPPORT_ATCALLS__ \
|| __MPLS_SDK_SUPPORT_SETATTRLISTAT__)
#define __MPLS_SDK_NEED_BEST_FCHDIR__ (__MPLS_SDK_SUPPORT_FDOPENDIR__ || __MPLS_SDK_SUPPORT_ATCALLS__ || __MPLS_SDK_SUPPORT_SETATTRLISTAT__)
#define __MPLS_LIB_NEED_BEST_FCHDIR__ (__MPLS_LIB_SUPPORT_FDOPENDIR__ || __MPLS_LIB_SUPPORT_ATCALLS__ || __MPLS_LIB_SUPPORT_SETATTRLISTAT__) #define __MPLS_SDK_NEED_BEST_FCHDIR__ (__MPLS_SDK_SUPPORT_FDOPENDIR__ \
|| __MPLS_SDK_SUPPORT_ATCALLS__ \
|| __MPLS_SDK_SUPPORT_SETATTRLISTAT__)
#define __MPLS_LIB_NEED_BEST_FCHDIR__ (__MPLS_LIB_SUPPORT_FDOPENDIR__ \
|| __MPLS_LIB_SUPPORT_ATCALLS__ \
|| __MPLS_LIB_SUPPORT_SETATTRLISTAT__)
#define __MPLS_LIB_SUPPORT_REALPATH_WRAP__ (__MPLS_LIB_SUPPORT_REALPATH_ALLOC__ \
|| __MPLS_LIB_SUPPORT_REALPATH_NONEX_FIX__)
/* UUIDs - for now, just add missing typedef statements */ /* UUIDs - for now, just add missing typedef statements */
#define __MPLS_SDK_SUPPORT_UUID__ (__MPLS_SDK_MAJOR < 1060) #define __MPLS_SDK_SUPPORT_UUID__ (__MPLS_SDK_MAJOR < 1060)
......
...@@ -5,7 +5,7 @@ extern const char posix_memalign_tmp4 __asm("$ld$add$os10.4$_posix_memalign"); _ ...@@ -5,7 +5,7 @@ extern const char posix_memalign_tmp4 __asm("$ld$add$os10.4$_posix_memalign"); _
extern const char posix_memalign_tmp5 __asm("$ld$add$os10.5$_posix_memalign"); __attribute__((visibility("default"))) const char posix_memalign_tmp5 = 0; extern const char posix_memalign_tmp5 __asm("$ld$add$os10.5$_posix_memalign"); __attribute__((visibility("default"))) const char posix_memalign_tmp5 = 0;
#endif #endif
#if !(__MPLS_LIB_SUPPORT_REALPATH_WRAP__) #if !(__MPLS_LIB_SUPPORT_REALPATH_ALLOC__)
extern const char realpath_tmp4 __asm("$ld$add$os10.4$_realpath"); __attribute__((visibility("default"))) const char realpath_tmp4 = 0; extern const char realpath_tmp4 __asm("$ld$add$os10.4$_realpath"); __attribute__((visibility("default"))) const char realpath_tmp4 = 0;
extern const char realpath_tmp5 __asm("$ld$add$os10.5$_realpath$DARWIN_EXTSN"); __attribute__((visibility("default"))) const char realpath_tmp5 = 0; extern const char realpath_tmp5 __asm("$ld$add$os10.5$_realpath$DARWIN_EXTSN"); __attribute__((visibility("default"))) const char realpath_tmp5 = 0;
#endif #endif
......
...@@ -54,8 +54,13 @@ ...@@ -54,8 +54,13 @@
/* Function type for realpath() */ /* Function type for realpath() */
typedef char *rp_func_t(const char * __restrict, char * __restrict); typedef char *rp_func_t(const char * __restrict, char * __restrict);
/* Macro defining all versions */ /*
/* Note that the UNIX2003 version never exists in 64-bit builds. */ * Macro defining all versions
* Note that the UNIX2003 version never exists in 64-bit builds.
* Also note that the 10.6 "nonext" fix only needs the basic version.
*/
# if __MPLS_LIB_SUPPORT_REALPATH_ALLOC__
#if !__MPLS_64BIT #if !__MPLS_64BIT
...@@ -72,6 +77,14 @@ typedef char *rp_func_t(const char * __restrict, char * __restrict); ...@@ -72,6 +77,14 @@ typedef char *rp_func_t(const char * __restrict, char * __restrict);
#endif /* 64-bit */ #endif /* 64-bit */
#endif /* __MPLS_LIB_SUPPORT_REALPATH_ALLOC__ */
#if __MPLS_LIB_SUPPORT_REALPATH_NONEX_FIX__
#define RP_ALL RP_ENT(,,basic)
#endif /* __MPLS_LIB_SUPPORT_REALPATH_NONEX_FIX__ */
/* Table of indices of versions */ /* Table of indices of versions */
#define RP_ENT(d,x,t) rp_##t, #define RP_ENT(d,x,t) rp_##t,
typedef enum { typedef enum {
...@@ -140,6 +153,8 @@ realpath##d##x(const char * __restrict file_name, \ ...@@ -140,6 +153,8 @@ realpath##d##x(const char * __restrict file_name, \
RP_ALL RP_ALL
#undef RP_ENT #undef RP_ENT
# if __MPLS_LIB_SUPPORT_REALPATH_ALLOC__
/* /*
* Compatibility function to avoid the need to rebuild existing binaries * Compatibility function to avoid the need to rebuild existing binaries
* built with the old wrapper-macro implementation (between Jan-2019 and * built with the old wrapper-macro implementation (between Jan-2019 and
...@@ -162,4 +177,6 @@ macports_legacy_realpath(const char * __restrict file_name, ...@@ -162,4 +177,6 @@ macports_legacy_realpath(const char * __restrict file_name,
return realpath_internal(file_name, resolved_name, RP_DEFAULT); return realpath_internal(file_name, resolved_name, RP_DEFAULT);
} }
#endif /* __MPLS_LIB_SUPPORT_REALPATH_ALLOC__ */
#endif /*__MPLS_LIB_SUPPORT_REALPATH_WRAP__*/ #endif /*__MPLS_LIB_SUPPORT_REALPATH_WRAP__*/
...@@ -12,14 +12,14 @@ ...@@ -12,14 +12,14 @@
/* MP support header */ /* MP support header */
#include "MacportsLegacySupport.h" #include "MacportsLegacySupport.h"
#if __MPLS_LIB_SUPPORT_REALPATH_WRAP__ #if __MPLS_LIB_SUPPORT_REALPATH_ALLOC__
#define TEST_MACPORTS_LEGACY_REALPATH #define TEST_MACPORTS_LEGACY_REALPATH
#include "test_realpath.c" #include "test_realpath.c"
#else /* !__MPLS_LIB_SUPPORT_REALPATH_WRAP__ */ #else /* !__MPLS_LIB_SUPPORT_REALPATH_ALLOC__ */
int main(){ return 0; } int main(){ return 0; }
#endif /* !__MPLS_LIB_SUPPORT_REALPATH_WRAP__ */ #endif /* !__MPLS_LIB_SUPPORT_REALPATH_ALLOC__ */
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment