]>
Commit | Line | Data |
---|---|---|
1 | /* | |
2 | * Copyright (c) 2007,2017 Apple Inc. All rights reserved. | |
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 | ||
31 | #include <sys/cdefs.h> | |
32 | #include <Availability.h> | |
33 | #include <secure/_common.h> | |
34 | ||
35 | #if _USE_FORTIFY_LEVEL > 0 | |
36 | ||
37 | /* <rdar://problem/12622659> */ | |
38 | #if defined(__clang__) && \ | |
39 | ((defined(__apple_build_version__) && __apple_build_version__ >= 4260006) || \ | |
40 | (!defined(__apple_build_version__) && (__clang_major__ > 3 || (__clang_major__ == 3 && __clang_minor__ >= 3)))) | |
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 | ||
49 | #if __IPHONE_OS_VERSION_MIN_REQUIRED >= 70000 || __MAC_OS_X_VERSION_MIN_REQUIRED >= 1090 | |
50 | #if __has_builtin(__builtin___memccpy_chk) && __HAS_FIXED_CHK_PROTOTYPES | |
51 | #undef memccpy | |
52 | /* void *memccpy(void *dst, const void *src, int c, size_t n) */ | |
53 | #define memccpy(dest, ...) \ | |
54 | __builtin___memccpy_chk (dest, __VA_ARGS__, __darwin_obsz0 (dest)) | |
55 | #endif | |
56 | #endif | |
57 | ||
58 | #if __has_builtin(__builtin___memcpy_chk) || defined(__GNUC__) | |
59 | #undef memcpy | |
60 | /* void *memcpy(void *dst, const void *src, size_t n) */ | |
61 | #define memcpy(dest, ...) \ | |
62 | __builtin___memcpy_chk (dest, __VA_ARGS__, __darwin_obsz0 (dest)) | |
63 | #endif | |
64 | ||
65 | #if __has_builtin(__builtin___memmove_chk) || defined(__GNUC__) | |
66 | #undef memmove | |
67 | /* void *memmove(void *dst, const void *src, size_t len) */ | |
68 | #define memmove(dest, ...) \ | |
69 | __builtin___memmove_chk (dest, __VA_ARGS__, __darwin_obsz0 (dest)) | |
70 | #endif | |
71 | ||
72 | #if __has_builtin(__builtin___memset_chk) || defined(__GNUC__) | |
73 | #undef memset | |
74 | /* void *memset(void *b, int c, size_t len) */ | |
75 | #define memset(dest, ...) \ | |
76 | __builtin___memset_chk (dest, __VA_ARGS__, __darwin_obsz0 (dest)) | |
77 | #endif | |
78 | ||
79 | #if __has_builtin(__builtin___strcpy_chk) || defined(__GNUC__) | |
80 | #undef strcpy | |
81 | /* char *strcpy(char *dst, const char *src) */ | |
82 | #define strcpy(dest, ...) \ | |
83 | __builtin___strcpy_chk (dest, __VA_ARGS__, __darwin_obsz (dest)) | |
84 | #endif | |
85 | ||
86 | #if __DARWIN_C_LEVEL >= 200809L | |
87 | #if __has_builtin(__builtin___stpcpy_chk) || defined(__GNUC__) | |
88 | #undef stpcpy | |
89 | /* char *stpcpy(char *dst, const char *src) */ | |
90 | #define stpcpy(dest, ...) \ | |
91 | __builtin___stpcpy_chk (dest, __VA_ARGS__, __darwin_obsz (dest)) | |
92 | #endif | |
93 | ||
94 | #if __has_builtin(__builtin___stpncpy_chk) || __APPLE_CC__ >= 5666 || __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 7) | |
95 | #undef stpncpy | |
96 | /* char *stpncpy(char *dst, const char *src, size_t n) */ | |
97 | #define stpncpy(dest, ...) \ | |
98 | __builtin___stpncpy_chk (dest, __VA_ARGS__, __darwin_obsz (dest)) | |
99 | #endif | |
100 | #endif /* _DARWIN_C_LEVEL >= 200809L */ | |
101 | ||
102 | #if __DARWIN_C_LEVEL >= __DARWIN_C_FULL | |
103 | #if __IPHONE_OS_VERSION_MIN_REQUIRED >= 70000 || __MAC_OS_X_VERSION_MIN_REQUIRED >= 1090 | |
104 | #if __has_builtin(__builtin___strlcpy_chk) && __HAS_FIXED_CHK_PROTOTYPES | |
105 | #undef strlcpy | |
106 | /* size_t strlcpy(char *dst, const char *source, size_t size) */ | |
107 | #define strlcpy(dest, ...) \ | |
108 | __builtin___strlcpy_chk (dest, __VA_ARGS__, __darwin_obsz (dest)) | |
109 | #endif | |
110 | ||
111 | #if __has_builtin(__builtin___strlcat_chk) && __HAS_FIXED_CHK_PROTOTYPES | |
112 | #undef strlcat | |
113 | /* size_t strlcat(char *dst, const char *source, size_t size) */ | |
114 | #define strlcat(dest, ...) \ | |
115 | __builtin___strlcat_chk (dest, __VA_ARGS__, __darwin_obsz (dest)) | |
116 | #endif | |
117 | #endif /* __IPHONE_OS_VERSION_MIN_REQUIRED >= 70000 || __MAC_OS_X_VERSION_MIN_REQUIRED >= 1090 */ | |
118 | #endif /* __DARWIN_C_LEVEL >= __DARWIN_C_FULL */ | |
119 | ||
120 | #if __has_builtin(__builtin___strncpy_chk) || defined(__GNUC__) | |
121 | #undef strncpy | |
122 | /* char *strncpy(char *dst, const char *src, size_t n) */ | |
123 | #define strncpy(dest, ...) \ | |
124 | __builtin___strncpy_chk (dest, __VA_ARGS__, __darwin_obsz (dest)) | |
125 | #endif | |
126 | ||
127 | #if __has_builtin(__builtin___strcat_chk) || defined(__GNUC__) | |
128 | #undef strcat | |
129 | /* char *strcat(char *s1, const char *s2) */ | |
130 | #define strcat(dest, ...) \ | |
131 | __builtin___strcat_chk (dest, __VA_ARGS__, __darwin_obsz (dest)) | |
132 | #endif | |
133 | ||
134 | #if ! (defined(__IPHONE_OS_VERSION_MIN_REQUIRED) && __IPHONE_OS_VERSION_MIN_REQUIRED < 32000) | |
135 | #if __has_builtin(__builtin___strncat_chk) || defined(__GNUC__) | |
136 | #undef strncat | |
137 | /* char *strncat(char *s1, const char *s2, size_t n) */ | |
138 | #define strncat(dest, ...) \ | |
139 | __builtin___strncat_chk (dest, __VA_ARGS__, __darwin_obsz (dest)) | |
140 | #endif | |
141 | #endif | |
142 | ||
143 | #undef __HAS_FIXED_CHK_PROTOTYPES | |
144 | ||
145 | #endif /* _USE_FORTIFY_LEVEL > 0 */ | |
146 | #endif /* _SECURE__STRING_H_ */ |