]>
Commit | Line | Data |
---|---|---|
224c7076 | 1 | /* |
b061a43b | 2 | * Copyright (c) 2007,2017 Apple Inc. All rights reserved. |
224c7076 A |
3 | * |
4 | * @APPLE_LICENSE_HEADER_START@ | |
5 | * | |
6 | * This file contains Original Code and/or Modifications of Original Code | |
7 | * as defined in and that are subject to the Apple Public Source License | |
8 | * Version 2.0 (the 'License'). You may not use this file except in | |
9 | * compliance with the License. Please obtain a copy of the License at | |
10 | * http://www.opensource.apple.com/apsl/ and read it before using this | |
11 | * file. | |
12 | * | |
13 | * The Original Code and all software distributed under the License are | |
14 | * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER | |
15 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, | |
16 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, | |
17 | * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. | |
18 | * Please see the License for the specific language governing rights and | |
19 | * limitations under the License. | |
20 | * | |
21 | * @APPLE_LICENSE_HEADER_END@ | |
22 | */ | |
23 | ||
24 | #ifndef _STRING_H_ | |
25 | # error "Never use <secure/_string.h> directly; include <string.h> instead." | |
26 | #endif | |
27 | ||
28 | #ifndef _SECURE__STRING_H_ | |
29 | #define _SECURE__STRING_H_ | |
30 | ||
34e8f829 | 31 | #include <sys/cdefs.h> |
b061a43b | 32 | #include <Availability.h> |
224c7076 A |
33 | #include <secure/_common.h> |
34 | ||
35 | #if _USE_FORTIFY_LEVEL > 0 | |
36 | ||
6465356a A |
37 | /* <rdar://problem/12622659> */ |
38 | #if defined(__clang__) && \ | |
b061a43b A |
39 | ((defined(__apple_build_version__) && __apple_build_version__ >= 4260006) || \ |
40 | (!defined(__apple_build_version__) && (__clang_major__ > 3 || (__clang_major__ == 3 && __clang_minor__ >= 3)))) | |
6465356a A |
41 | #define __HAS_FIXED_CHK_PROTOTYPES 1 |
42 | #else | |
43 | #define __HAS_FIXED_CHK_PROTOTYPES 0 | |
44 | #endif | |
45 | ||
46 | /* memccpy, memcpy, mempcpy, memmove, memset, strcpy, strlcpy, stpcpy, | |
47 | strncpy, stpncpy, strcat, strlcat, and strncat */ | |
48 | ||
507116e3 A |
49 | #if __IPHONE_OS_VERSION_MIN_REQUIRED >= 70000 || __MAC_OS_X_VERSION_MIN_REQUIRED >= 1090 || \ |
50 | defined(__DRIVERKIT_VERSION_MIN_REQUIRED) | |
6465356a A |
51 | #if __has_builtin(__builtin___memccpy_chk) && __HAS_FIXED_CHK_PROTOTYPES |
52 | #undef memccpy | |
b061a43b A |
53 | /* void *memccpy(void *dst, const void *src, int c, size_t n) */ |
54 | #define memccpy(dest, ...) \ | |
55 | __builtin___memccpy_chk (dest, __VA_ARGS__, __darwin_obsz0 (dest)) | |
1f2f436a | 56 | #endif |
1f2f436a | 57 | #endif |
224c7076 | 58 | |
6465356a A |
59 | #if __has_builtin(__builtin___memcpy_chk) || defined(__GNUC__) |
60 | #undef memcpy | |
b061a43b A |
61 | /* void *memcpy(void *dst, const void *src, size_t n) */ |
62 | #define memcpy(dest, ...) \ | |
63 | __builtin___memcpy_chk (dest, __VA_ARGS__, __darwin_obsz0 (dest)) | |
6465356a | 64 | #endif |
224c7076 | 65 | |
6465356a A |
66 | #if __has_builtin(__builtin___memmove_chk) || defined(__GNUC__) |
67 | #undef memmove | |
b061a43b A |
68 | /* void *memmove(void *dst, const void *src, size_t len) */ |
69 | #define memmove(dest, ...) \ | |
70 | __builtin___memmove_chk (dest, __VA_ARGS__, __darwin_obsz0 (dest)) | |
6465356a | 71 | #endif |
224c7076 | 72 | |
6465356a A |
73 | #if __has_builtin(__builtin___memset_chk) || defined(__GNUC__) |
74 | #undef memset | |
b061a43b A |
75 | /* void *memset(void *b, int c, size_t len) */ |
76 | #define memset(dest, ...) \ | |
77 | __builtin___memset_chk (dest, __VA_ARGS__, __darwin_obsz0 (dest)) | |
6465356a | 78 | #endif |
224c7076 | 79 | |
507116e3 | 80 | #ifndef UNIFDEF_DRIVERKIT |
6465356a A |
81 | #if __has_builtin(__builtin___strcpy_chk) || defined(__GNUC__) |
82 | #undef strcpy | |
b061a43b A |
83 | /* char *strcpy(char *dst, const char *src) */ |
84 | #define strcpy(dest, ...) \ | |
85 | __builtin___strcpy_chk (dest, __VA_ARGS__, __darwin_obsz (dest)) | |
6465356a | 86 | #endif |
224c7076 | 87 | |
1f2f436a | 88 | #if __DARWIN_C_LEVEL >= 200809L |
6465356a A |
89 | #if __has_builtin(__builtin___stpcpy_chk) || defined(__GNUC__) |
90 | #undef stpcpy | |
b061a43b A |
91 | /* char *stpcpy(char *dst, const char *src) */ |
92 | #define stpcpy(dest, ...) \ | |
93 | __builtin___stpcpy_chk (dest, __VA_ARGS__, __darwin_obsz (dest)) | |
6465356a | 94 | #endif |
507116e3 A |
95 | #endif /* __DARWIN_C_LEVEL >= 200809L */ |
96 | #endif /* UNIFDEF_DRIVERKIT */ | |
1f2f436a | 97 | |
507116e3 | 98 | #if __DARWIN_C_LEVEL >= 200809L |
6465356a A |
99 | #if __has_builtin(__builtin___stpncpy_chk) || __APPLE_CC__ >= 5666 || __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 7) |
100 | #undef stpncpy | |
b061a43b A |
101 | /* char *stpncpy(char *dst, const char *src, size_t n) */ |
102 | #define stpncpy(dest, ...) \ | |
103 | __builtin___stpncpy_chk (dest, __VA_ARGS__, __darwin_obsz (dest)) | |
6465356a A |
104 | #endif |
105 | #endif /* _DARWIN_C_LEVEL >= 200809L */ | |
106 | ||
107 | #if __DARWIN_C_LEVEL >= __DARWIN_C_FULL | |
507116e3 A |
108 | #if __IPHONE_OS_VERSION_MIN_REQUIRED >= 70000 || __MAC_OS_X_VERSION_MIN_REQUIRED >= 1090 || \ |
109 | defined(__DRIVERKIT_VERSION_MIN_REQUIRED) | |
6465356a A |
110 | #if __has_builtin(__builtin___strlcpy_chk) && __HAS_FIXED_CHK_PROTOTYPES |
111 | #undef strlcpy | |
b061a43b A |
112 | /* size_t strlcpy(char *dst, const char *source, size_t size) */ |
113 | #define strlcpy(dest, ...) \ | |
114 | __builtin___strlcpy_chk (dest, __VA_ARGS__, __darwin_obsz (dest)) | |
6465356a | 115 | #endif |
1f2f436a | 116 | |
6465356a A |
117 | #if __has_builtin(__builtin___strlcat_chk) && __HAS_FIXED_CHK_PROTOTYPES |
118 | #undef strlcat | |
b061a43b A |
119 | /* size_t strlcat(char *dst, const char *source, size_t size) */ |
120 | #define strlcat(dest, ...) \ | |
121 | __builtin___strlcat_chk (dest, __VA_ARGS__, __darwin_obsz (dest)) | |
1f2f436a | 122 | #endif |
6465356a A |
123 | #endif /* __IPHONE_OS_VERSION_MIN_REQUIRED >= 70000 || __MAC_OS_X_VERSION_MIN_REQUIRED >= 1090 */ |
124 | #endif /* __DARWIN_C_LEVEL >= __DARWIN_C_FULL */ | |
224c7076 | 125 | |
6465356a A |
126 | #if __has_builtin(__builtin___strncpy_chk) || defined(__GNUC__) |
127 | #undef strncpy | |
b061a43b A |
128 | /* char *strncpy(char *dst, const char *src, size_t n) */ |
129 | #define strncpy(dest, ...) \ | |
130 | __builtin___strncpy_chk (dest, __VA_ARGS__, __darwin_obsz (dest)) | |
6465356a | 131 | #endif |
224c7076 | 132 | |
507116e3 | 133 | #ifndef UNIFDEF_DRIVERKIT |
6465356a A |
134 | #if __has_builtin(__builtin___strcat_chk) || defined(__GNUC__) |
135 | #undef strcat | |
b061a43b A |
136 | /* char *strcat(char *s1, const char *s2) */ |
137 | #define strcat(dest, ...) \ | |
138 | __builtin___strcat_chk (dest, __VA_ARGS__, __darwin_obsz (dest)) | |
6465356a | 139 | #endif |
507116e3 | 140 | #endif /* UNIFDEF_DRIVERKIT */ |
224c7076 | 141 | |
1f2f436a | 142 | #if ! (defined(__IPHONE_OS_VERSION_MIN_REQUIRED) && __IPHONE_OS_VERSION_MIN_REQUIRED < 32000) |
6465356a A |
143 | #if __has_builtin(__builtin___strncat_chk) || defined(__GNUC__) |
144 | #undef strncat | |
b061a43b A |
145 | /* char *strncat(char *s1, const char *s2, size_t n) */ |
146 | #define strncat(dest, ...) \ | |
147 | __builtin___strncat_chk (dest, __VA_ARGS__, __darwin_obsz (dest)) | |
224c7076 A |
148 | #endif |
149 | #endif | |
6465356a A |
150 | |
151 | #undef __HAS_FIXED_CHK_PROTOTYPES | |
152 | ||
153 | #endif /* _USE_FORTIFY_LEVEL > 0 */ | |
154 | #endif /* _SECURE__STRING_H_ */ |