Nick Kralevich | 5bcf398 | 2013-06-28 10:34:09 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2013 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #include <gtest/gtest.h> |
Christopher Ferris | f04935c | 2013-12-20 18:43:21 -0800 | [diff] [blame] | 18 | #include <signal.h> |
Nick Kralevich | 5bcf398 | 2013-06-28 10:34:09 -0700 | [diff] [blame] | 19 | #include <string.h> |
| 20 | #include <stdarg.h> |
Nick Kralevich | a6cde39 | 2013-06-29 08:15:25 -0700 | [diff] [blame] | 21 | #include <sys/types.h> |
| 22 | #include <sys/stat.h> |
Nick Kralevich | 60f4f9a | 2013-09-24 16:32:07 -0700 | [diff] [blame] | 23 | #include <sys/socket.h> |
Nick Kralevich | b91791d | 2013-10-02 14:14:40 -0700 | [diff] [blame] | 24 | #include <malloc.h> |
Nick Kralevich | b036b5c | 2013-10-09 20:16:34 -0700 | [diff] [blame] | 25 | #include <fcntl.h> |
Nick Kralevich | be0e43b | 2014-07-23 13:56:23 -0700 | [diff] [blame] | 26 | #include <sys/prctl.h> |
Nick Kralevich | 5bcf398 | 2013-06-28 10:34:09 -0700 | [diff] [blame] | 27 | |
| 28 | // We have to say "DeathTest" here so gtest knows to run this test (which exits) |
| 29 | // in its own process. Unfortunately, the C preprocessor doesn't give us an |
| 30 | // easy way to concatenate strings, so we need to use the complicated method |
| 31 | // below. *sigh* |
| 32 | #define DEATHTEST_PASTER(name) name##_DeathTest |
| 33 | #define DEATHTEST_EVALUATOR(name) DEATHTEST_PASTER(name) |
| 34 | #define DEATHTEST DEATHTEST_EVALUATOR(TEST_NAME) |
| 35 | |
Nick Kralevich | be0e43b | 2014-07-23 13:56:23 -0700 | [diff] [blame] | 36 | class DEATHTEST : public testing::Test { |
| 37 | protected: |
| 38 | virtual void SetUp() { |
| 39 | old_dumpable_ = prctl(PR_GET_DUMPABLE, 0, 0, 0, 0); |
| 40 | // Suppress debuggerd stack traces. Too slow. |
| 41 | prctl(PR_SET_DUMPABLE, 0, 0, 0, 0); |
| 42 | } |
| 43 | |
| 44 | virtual void TearDown() { |
| 45 | prctl(PR_SET_DUMPABLE, old_dumpable_, 0, 0, 0, 0); |
| 46 | } |
| 47 | private: |
| 48 | int old_dumpable_; |
| 49 | }; |
| 50 | |
Nick Kralevich | 5bcf398 | 2013-06-28 10:34:09 -0700 | [diff] [blame] | 51 | #if defined(_FORTIFY_SOURCE) && _FORTIFY_SOURCE == 2 |
| 52 | struct foo { |
| 53 | char empty[0]; |
| 54 | char one[1]; |
| 55 | char a[10]; |
| 56 | char b[10]; |
| 57 | }; |
| 58 | |
| 59 | #ifndef __clang__ |
| 60 | // This test is disabled in clang because clang doesn't properly detect |
| 61 | // this buffer overflow. TODO: Fix clang. |
Nick Kralevich | be0e43b | 2014-07-23 13:56:23 -0700 | [diff] [blame] | 62 | TEST_F(DEATHTEST, stpncpy_fortified2) { |
Christopher Ferris | 950a58e | 2014-04-04 14:38:18 -0700 | [diff] [blame] | 63 | ::testing::FLAGS_gtest_death_test_style = "threadsafe"; |
| 64 | foo myfoo; |
| 65 | int copy_amt = atoi("11"); |
| 66 | ASSERT_EXIT(stpncpy(myfoo.a, "01234567890", copy_amt), |
| 67 | testing::KilledBySignal(SIGABRT), ""); |
| 68 | } |
| 69 | #endif |
| 70 | |
| 71 | #ifndef __clang__ |
| 72 | // This test is disabled in clang because clang doesn't properly detect |
| 73 | // this buffer overflow. TODO: Fix clang. |
Nick Kralevich | be0e43b | 2014-07-23 13:56:23 -0700 | [diff] [blame] | 74 | TEST_F(DEATHTEST, stpncpy2_fortified2) { |
Christopher Ferris | 950a58e | 2014-04-04 14:38:18 -0700 | [diff] [blame] | 75 | ::testing::FLAGS_gtest_death_test_style = "threadsafe"; |
| 76 | foo myfoo; |
| 77 | memset(&myfoo, 0, sizeof(myfoo)); |
| 78 | myfoo.one[0] = 'A'; // not null terminated string |
| 79 | ASSERT_EXIT(stpncpy(myfoo.b, myfoo.one, sizeof(myfoo.b)), |
| 80 | testing::KilledBySignal(SIGABRT), ""); |
| 81 | } |
| 82 | #endif |
| 83 | |
| 84 | #ifndef __clang__ |
| 85 | // This test is disabled in clang because clang doesn't properly detect |
| 86 | // this buffer overflow. TODO: Fix clang. |
Nick Kralevich | be0e43b | 2014-07-23 13:56:23 -0700 | [diff] [blame] | 87 | TEST_F(DEATHTEST, strncpy_fortified2) { |
Nick Kralevich | 5bcf398 | 2013-06-28 10:34:09 -0700 | [diff] [blame] | 88 | ::testing::FLAGS_gtest_death_test_style = "threadsafe"; |
| 89 | foo myfoo; |
| 90 | int copy_amt = atoi("11"); |
| 91 | ASSERT_EXIT(strncpy(myfoo.a, "01234567890", copy_amt), |
| 92 | testing::KilledBySignal(SIGABRT), ""); |
| 93 | } |
| 94 | #endif |
| 95 | |
| 96 | #ifndef __clang__ |
| 97 | // This test is disabled in clang because clang doesn't properly detect |
| 98 | // this buffer overflow. TODO: Fix clang. |
Nick Kralevich | be0e43b | 2014-07-23 13:56:23 -0700 | [diff] [blame] | 99 | TEST_F(DEATHTEST, strncpy2_fortified2) { |
Nick Kralevich | 93501d3 | 2013-08-28 10:47:43 -0700 | [diff] [blame] | 100 | ::testing::FLAGS_gtest_death_test_style = "threadsafe"; |
| 101 | foo myfoo; |
| 102 | memset(&myfoo, 0, sizeof(myfoo)); |
| 103 | myfoo.one[0] = 'A'; // not null terminated string |
| 104 | ASSERT_EXIT(strncpy(myfoo.b, myfoo.one, sizeof(myfoo.b)), |
| 105 | testing::KilledBySignal(SIGABRT), ""); |
| 106 | } |
| 107 | #endif |
| 108 | |
| 109 | #ifndef __clang__ |
| 110 | // This test is disabled in clang because clang doesn't properly detect |
| 111 | // this buffer overflow. TODO: Fix clang. |
Nick Kralevich | be0e43b | 2014-07-23 13:56:23 -0700 | [diff] [blame] | 112 | TEST_F(DEATHTEST, sprintf_fortified2) { |
Nick Kralevich | 5bcf398 | 2013-06-28 10:34:09 -0700 | [diff] [blame] | 113 | ::testing::FLAGS_gtest_death_test_style = "threadsafe"; |
| 114 | foo myfoo; |
| 115 | char source_buf[15]; |
| 116 | memcpy(source_buf, "12345678901234", 15); |
| 117 | ASSERT_EXIT(sprintf(myfoo.a, "%s", source_buf), |
| 118 | testing::KilledBySignal(SIGABRT), ""); |
| 119 | } |
| 120 | #endif |
| 121 | |
| 122 | #ifndef __clang__ |
Nick Kralevich | 5bcf398 | 2013-06-28 10:34:09 -0700 | [diff] [blame] | 123 | // These tests are disabled in clang because clang doesn't properly detect |
| 124 | // this buffer overflow. TODO: Fix clang. |
| 125 | static int vsprintf_helper2(const char *fmt, ...) { |
| 126 | foo myfoo; |
| 127 | va_list va; |
| 128 | int result; |
| 129 | |
| 130 | va_start(va, fmt); |
| 131 | result = vsprintf(myfoo.a, fmt, va); // should crash here |
| 132 | va_end(va); |
| 133 | return result; |
| 134 | } |
| 135 | |
Nick Kralevich | be0e43b | 2014-07-23 13:56:23 -0700 | [diff] [blame] | 136 | TEST_F(DEATHTEST, vsprintf_fortified2) { |
Nick Kralevich | 5bcf398 | 2013-06-28 10:34:09 -0700 | [diff] [blame] | 137 | ::testing::FLAGS_gtest_death_test_style = "threadsafe"; |
| 138 | ASSERT_EXIT(vsprintf_helper2("%s", "0123456789"), testing::KilledBySignal(SIGABRT), ""); |
| 139 | } |
| 140 | |
Nick Kralevich | be0e43b | 2014-07-23 13:56:23 -0700 | [diff] [blame] | 141 | TEST_F(DEATHTEST, vsprintf2_fortified2) { |
Nick Kralevich | 5bcf398 | 2013-06-28 10:34:09 -0700 | [diff] [blame] | 142 | ::testing::FLAGS_gtest_death_test_style = "threadsafe"; |
| 143 | ASSERT_EXIT(vsprintf_helper2("0123456789"), testing::KilledBySignal(SIGABRT), ""); |
| 144 | } |
| 145 | #endif |
| 146 | |
| 147 | #ifndef __clang__ |
| 148 | // These tests are disabled in clang because clang doesn't properly detect |
| 149 | // this buffer overflow. TODO: Fix clang. |
| 150 | static int vsnprintf_helper2(const char *fmt, ...) { |
| 151 | foo myfoo; |
| 152 | va_list va; |
| 153 | int result; |
| 154 | size_t size = atoi("11"); |
| 155 | |
| 156 | va_start(va, fmt); |
| 157 | result = vsnprintf(myfoo.a, size, fmt, va); // should crash here |
| 158 | va_end(va); |
| 159 | return result; |
| 160 | } |
| 161 | |
Nick Kralevich | be0e43b | 2014-07-23 13:56:23 -0700 | [diff] [blame] | 162 | TEST_F(DEATHTEST, vsnprintf_fortified2) { |
Nick Kralevich | 5bcf398 | 2013-06-28 10:34:09 -0700 | [diff] [blame] | 163 | ::testing::FLAGS_gtest_death_test_style = "threadsafe"; |
| 164 | ASSERT_EXIT(vsnprintf_helper2("%s", "0123456789"), testing::KilledBySignal(SIGABRT), ""); |
| 165 | } |
| 166 | |
Nick Kralevich | be0e43b | 2014-07-23 13:56:23 -0700 | [diff] [blame] | 167 | TEST_F(DEATHTEST, vsnprintf2_fortified2) { |
Nick Kralevich | 5bcf398 | 2013-06-28 10:34:09 -0700 | [diff] [blame] | 168 | ::testing::FLAGS_gtest_death_test_style = "threadsafe"; |
| 169 | ASSERT_EXIT(vsnprintf_helper2("0123456789"), testing::KilledBySignal(SIGABRT), ""); |
| 170 | } |
| 171 | #endif |
| 172 | |
Nick Kralevich | 5bcf398 | 2013-06-28 10:34:09 -0700 | [diff] [blame] | 173 | #ifndef __clang__ |
| 174 | // zero sized target with "\0" source (should fail) |
| 175 | // This test is disabled in clang because clang doesn't properly detect |
| 176 | // this buffer overflow. TODO: Fix clang. |
Nick Kralevich | be0e43b | 2014-07-23 13:56:23 -0700 | [diff] [blame] | 177 | TEST_F(DEATHTEST, stpcpy_fortified2) { |
Christopher Ferris | 950a58e | 2014-04-04 14:38:18 -0700 | [diff] [blame] | 178 | #if defined(__BIONIC__) |
| 179 | ::testing::FLAGS_gtest_death_test_style = "threadsafe"; |
| 180 | foo myfoo; |
| 181 | char* src = strdup(""); |
| 182 | ASSERT_EXIT(stpcpy(myfoo.empty, src), |
| 183 | testing::KilledBySignal(SIGABRT), ""); |
| 184 | free(src); |
| 185 | #else // __BIONIC__ |
| 186 | GTEST_LOG_(INFO) << "This test does nothing.\n"; |
| 187 | #endif // __BIONIC__ |
| 188 | } |
| 189 | #endif |
| 190 | |
| 191 | #ifndef __clang__ |
| 192 | // zero sized target with "\0" source (should fail) |
| 193 | // This test is disabled in clang because clang doesn't properly detect |
| 194 | // this buffer overflow. TODO: Fix clang. |
Nick Kralevich | be0e43b | 2014-07-23 13:56:23 -0700 | [diff] [blame] | 195 | TEST_F(DEATHTEST, strcpy_fortified2) { |
Christopher Ferris | f04935c | 2013-12-20 18:43:21 -0800 | [diff] [blame] | 196 | #if defined(__BIONIC__) |
Nick Kralevich | 5bcf398 | 2013-06-28 10:34:09 -0700 | [diff] [blame] | 197 | ::testing::FLAGS_gtest_death_test_style = "threadsafe"; |
| 198 | foo myfoo; |
| 199 | char* src = strdup(""); |
| 200 | ASSERT_EXIT(strcpy(myfoo.empty, src), |
| 201 | testing::KilledBySignal(SIGABRT), ""); |
| 202 | free(src); |
Christopher Ferris | f04935c | 2013-12-20 18:43:21 -0800 | [diff] [blame] | 203 | #else // __BIONIC__ |
| 204 | GTEST_LOG_(INFO) << "This test does nothing.\n"; |
| 205 | #endif // __BIONIC__ |
Nick Kralevich | 5bcf398 | 2013-06-28 10:34:09 -0700 | [diff] [blame] | 206 | } |
| 207 | #endif |
| 208 | |
| 209 | #ifndef __clang__ |
| 210 | // zero sized target with longer source (should fail) |
| 211 | // This test is disabled in clang because clang doesn't properly detect |
| 212 | // this buffer overflow. TODO: Fix clang. |
Nick Kralevich | be0e43b | 2014-07-23 13:56:23 -0700 | [diff] [blame] | 213 | TEST_F(DEATHTEST, strcpy2_fortified2) { |
Christopher Ferris | f04935c | 2013-12-20 18:43:21 -0800 | [diff] [blame] | 214 | #if defined(__BIONIC__) |
Nick Kralevich | 5bcf398 | 2013-06-28 10:34:09 -0700 | [diff] [blame] | 215 | ::testing::FLAGS_gtest_death_test_style = "threadsafe"; |
| 216 | foo myfoo; |
| 217 | char* src = strdup("1"); |
| 218 | ASSERT_EXIT(strcpy(myfoo.empty, src), |
| 219 | testing::KilledBySignal(SIGABRT), ""); |
| 220 | free(src); |
Christopher Ferris | f04935c | 2013-12-20 18:43:21 -0800 | [diff] [blame] | 221 | #else // __BIONIC__ |
| 222 | GTEST_LOG_(INFO) << "This test does nothing.\n"; |
| 223 | #endif // __BIONIC__ |
Nick Kralevich | 5bcf398 | 2013-06-28 10:34:09 -0700 | [diff] [blame] | 224 | } |
| 225 | #endif |
| 226 | |
| 227 | #ifndef __clang__ |
| 228 | // one byte target with longer source (should fail) |
| 229 | // This test is disabled in clang because clang doesn't properly detect |
| 230 | // this buffer overflow. TODO: Fix clang. |
Nick Kralevich | be0e43b | 2014-07-23 13:56:23 -0700 | [diff] [blame] | 231 | TEST_F(DEATHTEST, strcpy3_fortified2) { |
Christopher Ferris | f04935c | 2013-12-20 18:43:21 -0800 | [diff] [blame] | 232 | #if defined(__BIONIC__) |
Nick Kralevich | 5bcf398 | 2013-06-28 10:34:09 -0700 | [diff] [blame] | 233 | ::testing::FLAGS_gtest_death_test_style = "threadsafe"; |
| 234 | foo myfoo; |
| 235 | char* src = strdup("12"); |
| 236 | ASSERT_EXIT(strcpy(myfoo.one, src), |
| 237 | testing::KilledBySignal(SIGABRT), ""); |
| 238 | free(src); |
Christopher Ferris | f04935c | 2013-12-20 18:43:21 -0800 | [diff] [blame] | 239 | #else // __BIONIC__ |
| 240 | GTEST_LOG_(INFO) << "This test does nothing.\n"; |
| 241 | #endif // __BIONIC__ |
Nick Kralevich | 5bcf398 | 2013-06-28 10:34:09 -0700 | [diff] [blame] | 242 | } |
| 243 | #endif |
| 244 | |
| 245 | #ifndef __clang__ |
| 246 | // This test is disabled in clang because clang doesn't properly detect |
| 247 | // this buffer overflow. TODO: Fix clang. |
Nick Kralevich | be0e43b | 2014-07-23 13:56:23 -0700 | [diff] [blame] | 248 | TEST_F(DEATHTEST, strchr_fortified2) { |
Christopher Ferris | f04935c | 2013-12-20 18:43:21 -0800 | [diff] [blame] | 249 | #if defined(__BIONIC__) |
Nick Kralevich | 5bcf398 | 2013-06-28 10:34:09 -0700 | [diff] [blame] | 250 | ::testing::FLAGS_gtest_death_test_style = "threadsafe"; |
| 251 | foo myfoo; |
| 252 | memcpy(myfoo.a, "0123456789", sizeof(myfoo.a)); |
| 253 | myfoo.b[0] = '\0'; |
| 254 | ASSERT_EXIT(printf("%s", strchr(myfoo.a, 'a')), |
| 255 | testing::KilledBySignal(SIGABRT), ""); |
Christopher Ferris | f04935c | 2013-12-20 18:43:21 -0800 | [diff] [blame] | 256 | #else // __BIONIC__ |
| 257 | GTEST_LOG_(INFO) << "This test does nothing.\n"; |
| 258 | #endif // __BIONIC__ |
Nick Kralevich | 5bcf398 | 2013-06-28 10:34:09 -0700 | [diff] [blame] | 259 | } |
| 260 | #endif |
| 261 | |
| 262 | #ifndef __clang__ |
| 263 | // This test is disabled in clang because clang doesn't properly detect |
| 264 | // this buffer overflow. TODO: Fix clang. |
Nick Kralevich | be0e43b | 2014-07-23 13:56:23 -0700 | [diff] [blame] | 265 | TEST_F(DEATHTEST, strrchr_fortified2) { |
Christopher Ferris | f04935c | 2013-12-20 18:43:21 -0800 | [diff] [blame] | 266 | #if defined(__BIONIC__) |
Nick Kralevich | 5bcf398 | 2013-06-28 10:34:09 -0700 | [diff] [blame] | 267 | ::testing::FLAGS_gtest_death_test_style = "threadsafe"; |
| 268 | foo myfoo; |
| 269 | memcpy(myfoo.a, "0123456789", 10); |
| 270 | memcpy(myfoo.b, "01234", 6); |
| 271 | ASSERT_EXIT(printf("%s", strrchr(myfoo.a, 'a')), |
| 272 | testing::KilledBySignal(SIGABRT), ""); |
Christopher Ferris | f04935c | 2013-12-20 18:43:21 -0800 | [diff] [blame] | 273 | #else // __BIONIC__ |
| 274 | GTEST_LOG_(INFO) << "This test does nothing.\n"; |
| 275 | #endif // __BIONIC__ |
Nick Kralevich | 5bcf398 | 2013-06-28 10:34:09 -0700 | [diff] [blame] | 276 | } |
| 277 | #endif |
| 278 | |
| 279 | #ifndef __clang__ |
| 280 | // This test is disabled in clang because clang doesn't properly detect |
| 281 | // this buffer overflow. TODO: Fix clang. |
Nick Kralevich | be0e43b | 2014-07-23 13:56:23 -0700 | [diff] [blame] | 282 | TEST_F(DEATHTEST, strlcpy_fortified2) { |
Christopher Ferris | f04935c | 2013-12-20 18:43:21 -0800 | [diff] [blame] | 283 | #if defined(__BIONIC__) |
Nick Kralevich | 5bcf398 | 2013-06-28 10:34:09 -0700 | [diff] [blame] | 284 | ::testing::FLAGS_gtest_death_test_style = "threadsafe"; |
| 285 | foo myfoo; |
| 286 | strcpy(myfoo.a, "01"); |
| 287 | size_t n = strlen(myfoo.a); |
| 288 | ASSERT_EXIT(strlcpy(myfoo.one, myfoo.a, n), |
| 289 | testing::KilledBySignal(SIGABRT), ""); |
Christopher Ferris | f04935c | 2013-12-20 18:43:21 -0800 | [diff] [blame] | 290 | #else // __BIONIC__ |
| 291 | GTEST_LOG_(INFO) << "This test does nothing.\n"; |
| 292 | #endif // __BIONIC__ |
Nick Kralevich | 5bcf398 | 2013-06-28 10:34:09 -0700 | [diff] [blame] | 293 | } |
| 294 | #endif |
| 295 | |
Nick Kralevich | a6cde39 | 2013-06-29 08:15:25 -0700 | [diff] [blame] | 296 | #ifndef __clang__ |
| 297 | // This test is disabled in clang because clang doesn't properly detect |
| 298 | // this buffer overflow. TODO: Fix clang. |
Nick Kralevich | be0e43b | 2014-07-23 13:56:23 -0700 | [diff] [blame] | 299 | TEST_F(DEATHTEST, strlcat_fortified2) { |
Christopher Ferris | f04935c | 2013-12-20 18:43:21 -0800 | [diff] [blame] | 300 | #if defined(__BIONIC__) |
Nick Kralevich | a6cde39 | 2013-06-29 08:15:25 -0700 | [diff] [blame] | 301 | ::testing::FLAGS_gtest_death_test_style = "threadsafe"; |
| 302 | foo myfoo; |
| 303 | strcpy(myfoo.a, "01"); |
| 304 | myfoo.one[0] = '\0'; |
| 305 | size_t n = strlen(myfoo.a); |
| 306 | ASSERT_EXIT(strlcat(myfoo.one, myfoo.a, n), |
| 307 | testing::KilledBySignal(SIGABRT), ""); |
Christopher Ferris | f04935c | 2013-12-20 18:43:21 -0800 | [diff] [blame] | 308 | #else // __BIONIC__ |
| 309 | GTEST_LOG_(INFO) << "This test does nothing.\n"; |
| 310 | #endif // __BIONIC__ |
Nick Kralevich | a6cde39 | 2013-06-29 08:15:25 -0700 | [diff] [blame] | 311 | } |
| 312 | #endif |
| 313 | |
Nick Kralevich | 5bcf398 | 2013-06-28 10:34:09 -0700 | [diff] [blame] | 314 | #ifndef __clang__ |
| 315 | // This test is disabled in clang because clang doesn't properly detect |
| 316 | // this buffer overflow. TODO: Fix clang. |
Nick Kralevich | be0e43b | 2014-07-23 13:56:23 -0700 | [diff] [blame] | 317 | TEST_F(DEATHTEST, strncat_fortified2) { |
Nick Kralevich | 5bcf398 | 2013-06-28 10:34:09 -0700 | [diff] [blame] | 318 | ::testing::FLAGS_gtest_death_test_style = "threadsafe"; |
| 319 | foo myfoo; |
| 320 | size_t n = atoi("10"); // avoid compiler optimizations |
| 321 | strncpy(myfoo.a, "012345678", n); |
| 322 | ASSERT_EXIT(strncat(myfoo.a, "9", n), testing::KilledBySignal(SIGABRT), ""); |
| 323 | } |
| 324 | #endif |
| 325 | |
| 326 | #ifndef __clang__ |
| 327 | // This test is disabled in clang because clang doesn't properly detect |
| 328 | // this buffer overflow. TODO: Fix clang. |
Nick Kralevich | be0e43b | 2014-07-23 13:56:23 -0700 | [diff] [blame] | 329 | TEST_F(DEATHTEST, strncat2_fortified2) { |
Nick Kralevich | 5bcf398 | 2013-06-28 10:34:09 -0700 | [diff] [blame] | 330 | ::testing::FLAGS_gtest_death_test_style = "threadsafe"; |
| 331 | foo myfoo; |
| 332 | myfoo.a[0] = '\0'; |
| 333 | size_t n = atoi("10"); // avoid compiler optimizations |
| 334 | ASSERT_EXIT(strncat(myfoo.a, "0123456789", n), testing::KilledBySignal(SIGABRT), ""); |
| 335 | } |
| 336 | #endif |
| 337 | |
Nick Kralevich | be0e43b | 2014-07-23 13:56:23 -0700 | [diff] [blame] | 338 | TEST_F(DEATHTEST, strncat3_fortified2) { |
Nick Kralevich | 5bcf398 | 2013-06-28 10:34:09 -0700 | [diff] [blame] | 339 | ::testing::FLAGS_gtest_death_test_style = "threadsafe"; |
| 340 | foo myfoo; |
| 341 | memcpy(myfoo.a, "0123456789", sizeof(myfoo.a)); // unterminated string |
| 342 | myfoo.b[0] = '\0'; |
| 343 | size_t n = atoi("10"); // avoid compiler optimizations |
| 344 | ASSERT_EXIT(strncat(myfoo.b, myfoo.a, n), testing::KilledBySignal(SIGABRT), ""); |
| 345 | } |
| 346 | |
| 347 | #ifndef __clang__ |
| 348 | // This test is disabled in clang because clang doesn't properly detect |
| 349 | // this buffer overflow. TODO: Fix clang. |
Nick Kralevich | be0e43b | 2014-07-23 13:56:23 -0700 | [diff] [blame] | 350 | TEST_F(DEATHTEST, strcat_fortified2) { |
Nick Kralevich | 5bcf398 | 2013-06-28 10:34:09 -0700 | [diff] [blame] | 351 | ::testing::FLAGS_gtest_death_test_style = "threadsafe"; |
| 352 | char src[11]; |
| 353 | strcpy(src, "0123456789"); |
| 354 | foo myfoo; |
| 355 | myfoo.a[0] = '\0'; |
| 356 | ASSERT_EXIT(strcat(myfoo.a, src), testing::KilledBySignal(SIGABRT), ""); |
| 357 | } |
| 358 | #endif |
| 359 | |
Nick Kralevich | be0e43b | 2014-07-23 13:56:23 -0700 | [diff] [blame] | 360 | TEST_F(DEATHTEST, strcat2_fortified2) { |
Nick Kralevich | 5bcf398 | 2013-06-28 10:34:09 -0700 | [diff] [blame] | 361 | ::testing::FLAGS_gtest_death_test_style = "threadsafe"; |
| 362 | foo myfoo; |
| 363 | memcpy(myfoo.a, "0123456789", sizeof(myfoo.a)); // unterminated string |
| 364 | myfoo.b[0] = '\0'; |
| 365 | ASSERT_EXIT(strcat(myfoo.b, myfoo.a), testing::KilledBySignal(SIGABRT), ""); |
| 366 | } |
| 367 | |
Nick Kralevich | be0e43b | 2014-07-23 13:56:23 -0700 | [diff] [blame] | 368 | TEST_F(DEATHTEST, snprintf_fortified2) { |
Nick Kralevich | 5bcf398 | 2013-06-28 10:34:09 -0700 | [diff] [blame] | 369 | ::testing::FLAGS_gtest_death_test_style = "threadsafe"; |
| 370 | foo myfoo; |
| 371 | strcpy(myfoo.a, "012345678"); |
| 372 | size_t n = strlen(myfoo.a) + 2; |
| 373 | ASSERT_EXIT(snprintf(myfoo.b, n, "a%s", myfoo.a), testing::KilledBySignal(SIGABRT), ""); |
| 374 | } |
| 375 | |
Nick Kralevich | be0e43b | 2014-07-23 13:56:23 -0700 | [diff] [blame] | 376 | TEST_F(DEATHTEST, bzero_fortified2) { |
Nick Kralevich | a6cde39 | 2013-06-29 08:15:25 -0700 | [diff] [blame] | 377 | ::testing::FLAGS_gtest_death_test_style = "threadsafe"; |
| 378 | foo myfoo; |
| 379 | memcpy(myfoo.b, "0123456789", sizeof(myfoo.b)); |
| 380 | size_t n = atoi("11"); |
| 381 | ASSERT_EXIT(bzero(myfoo.b, n), testing::KilledBySignal(SIGABRT), ""); |
| 382 | } |
| 383 | |
Nick Kralevich | 5bcf398 | 2013-06-28 10:34:09 -0700 | [diff] [blame] | 384 | #endif /* defined(_FORTIFY_SOURCE) && _FORTIFY_SOURCE=2 */ |
| 385 | |
Nick Kralevich | 5bcf398 | 2013-06-28 10:34:09 -0700 | [diff] [blame] | 386 | // multibyte target where we over fill (should fail) |
Nick Kralevich | be0e43b | 2014-07-23 13:56:23 -0700 | [diff] [blame] | 387 | TEST_F(DEATHTEST, strcpy_fortified) { |
Christopher Ferris | f04935c | 2013-12-20 18:43:21 -0800 | [diff] [blame] | 388 | #if defined(__BIONIC__) |
Nick Kralevich | 5bcf398 | 2013-06-28 10:34:09 -0700 | [diff] [blame] | 389 | ::testing::FLAGS_gtest_death_test_style = "threadsafe"; |
| 390 | char buf[10]; |
| 391 | char *orig = strdup("0123456789"); |
| 392 | ASSERT_EXIT(strcpy(buf, orig), testing::KilledBySignal(SIGABRT), ""); |
| 393 | free(orig); |
Christopher Ferris | f04935c | 2013-12-20 18:43:21 -0800 | [diff] [blame] | 394 | #else // __BIONIC__ |
| 395 | GTEST_LOG_(INFO) << "This test does nothing.\n"; |
| 396 | #endif // __BIONIC__ |
Nick Kralevich | 5bcf398 | 2013-06-28 10:34:09 -0700 | [diff] [blame] | 397 | } |
| 398 | |
| 399 | // zero sized target with "\0" source (should fail) |
Nick Kralevich | be0e43b | 2014-07-23 13:56:23 -0700 | [diff] [blame] | 400 | TEST_F(DEATHTEST, strcpy2_fortified) { |
Christopher Ferris | f04935c | 2013-12-20 18:43:21 -0800 | [diff] [blame] | 401 | #if defined(__BIONIC__) |
Nick Kralevich | 5bcf398 | 2013-06-28 10:34:09 -0700 | [diff] [blame] | 402 | ::testing::FLAGS_gtest_death_test_style = "threadsafe"; |
| 403 | char buf[0]; |
| 404 | char *orig = strdup(""); |
| 405 | ASSERT_EXIT(strcpy(buf, orig), testing::KilledBySignal(SIGABRT), ""); |
| 406 | free(orig); |
Christopher Ferris | f04935c | 2013-12-20 18:43:21 -0800 | [diff] [blame] | 407 | #else // __BIONIC__ |
| 408 | GTEST_LOG_(INFO) << "This test does nothing.\n"; |
| 409 | #endif // __BIONIC__ |
Nick Kralevich | 5bcf398 | 2013-06-28 10:34:09 -0700 | [diff] [blame] | 410 | } |
| 411 | |
| 412 | // zero sized target with longer source (should fail) |
Nick Kralevich | be0e43b | 2014-07-23 13:56:23 -0700 | [diff] [blame] | 413 | TEST_F(DEATHTEST, strcpy3_fortified) { |
Christopher Ferris | f04935c | 2013-12-20 18:43:21 -0800 | [diff] [blame] | 414 | #if defined(__BIONIC__) |
Nick Kralevich | 5bcf398 | 2013-06-28 10:34:09 -0700 | [diff] [blame] | 415 | ::testing::FLAGS_gtest_death_test_style = "threadsafe"; |
| 416 | char buf[0]; |
| 417 | char *orig = strdup("1"); |
| 418 | ASSERT_EXIT(strcpy(buf, orig), testing::KilledBySignal(SIGABRT), ""); |
| 419 | free(orig); |
Christopher Ferris | f04935c | 2013-12-20 18:43:21 -0800 | [diff] [blame] | 420 | #else // __BIONIC__ |
| 421 | GTEST_LOG_(INFO) << "This test does nothing.\n"; |
| 422 | #endif // __BIONIC__ |
Nick Kralevich | 5bcf398 | 2013-06-28 10:34:09 -0700 | [diff] [blame] | 423 | } |
| 424 | |
| 425 | // one byte target with longer source (should fail) |
Nick Kralevich | be0e43b | 2014-07-23 13:56:23 -0700 | [diff] [blame] | 426 | TEST_F(DEATHTEST, strcpy4_fortified) { |
Christopher Ferris | f04935c | 2013-12-20 18:43:21 -0800 | [diff] [blame] | 427 | #if defined(__BIONIC__) |
Nick Kralevich | 5bcf398 | 2013-06-28 10:34:09 -0700 | [diff] [blame] | 428 | ::testing::FLAGS_gtest_death_test_style = "threadsafe"; |
| 429 | char buf[1]; |
| 430 | char *orig = strdup("12"); |
| 431 | ASSERT_EXIT(strcpy(buf, orig), testing::KilledBySignal(SIGABRT), ""); |
| 432 | free(orig); |
Christopher Ferris | f04935c | 2013-12-20 18:43:21 -0800 | [diff] [blame] | 433 | #else // __BIONIC__ |
| 434 | GTEST_LOG_(INFO) << "This test does nothing.\n"; |
| 435 | #endif // __BIONIC__ |
Nick Kralevich | 5bcf398 | 2013-06-28 10:34:09 -0700 | [diff] [blame] | 436 | } |
| 437 | |
Nick Kralevich | be0e43b | 2014-07-23 13:56:23 -0700 | [diff] [blame] | 438 | TEST_F(DEATHTEST, strlen_fortified) { |
Christopher Ferris | f04935c | 2013-12-20 18:43:21 -0800 | [diff] [blame] | 439 | #if defined(__BIONIC__) |
Nick Kralevich | 5bcf398 | 2013-06-28 10:34:09 -0700 | [diff] [blame] | 440 | ::testing::FLAGS_gtest_death_test_style = "threadsafe"; |
| 441 | char buf[10]; |
| 442 | memcpy(buf, "0123456789", sizeof(buf)); |
Elliott Hughes | 5b9310e | 2013-10-02 16:59:05 -0700 | [diff] [blame] | 443 | ASSERT_EXIT(printf("%zd", strlen(buf)), testing::KilledBySignal(SIGABRT), ""); |
Christopher Ferris | f04935c | 2013-12-20 18:43:21 -0800 | [diff] [blame] | 444 | #else // __BIONIC__ |
| 445 | GTEST_LOG_(INFO) << "This test does nothing.\n"; |
| 446 | #endif // __BIONIC__ |
Nick Kralevich | 5bcf398 | 2013-06-28 10:34:09 -0700 | [diff] [blame] | 447 | } |
| 448 | |
Nick Kralevich | be0e43b | 2014-07-23 13:56:23 -0700 | [diff] [blame] | 449 | TEST_F(DEATHTEST, strchr_fortified) { |
Christopher Ferris | f04935c | 2013-12-20 18:43:21 -0800 | [diff] [blame] | 450 | #if defined(__BIONIC__) |
Nick Kralevich | 5bcf398 | 2013-06-28 10:34:09 -0700 | [diff] [blame] | 451 | ::testing::FLAGS_gtest_death_test_style = "threadsafe"; |
| 452 | char buf[10]; |
| 453 | memcpy(buf, "0123456789", sizeof(buf)); |
| 454 | ASSERT_EXIT(printf("%s", strchr(buf, 'a')), testing::KilledBySignal(SIGABRT), ""); |
Christopher Ferris | f04935c | 2013-12-20 18:43:21 -0800 | [diff] [blame] | 455 | #else // __BIONIC__ |
| 456 | GTEST_LOG_(INFO) << "This test does nothing.\n"; |
| 457 | #endif // __BIONIC__ |
Nick Kralevich | 5bcf398 | 2013-06-28 10:34:09 -0700 | [diff] [blame] | 458 | } |
| 459 | |
Nick Kralevich | be0e43b | 2014-07-23 13:56:23 -0700 | [diff] [blame] | 460 | TEST_F(DEATHTEST, strrchr_fortified) { |
Christopher Ferris | f04935c | 2013-12-20 18:43:21 -0800 | [diff] [blame] | 461 | #if defined(__BIONIC__) |
Nick Kralevich | 5bcf398 | 2013-06-28 10:34:09 -0700 | [diff] [blame] | 462 | ::testing::FLAGS_gtest_death_test_style = "threadsafe"; |
| 463 | char buf[10]; |
| 464 | memcpy(buf, "0123456789", sizeof(buf)); |
| 465 | ASSERT_EXIT(printf("%s", strrchr(buf, 'a')), testing::KilledBySignal(SIGABRT), ""); |
Christopher Ferris | f04935c | 2013-12-20 18:43:21 -0800 | [diff] [blame] | 466 | #else // __BIONIC__ |
| 467 | GTEST_LOG_(INFO) << "This test does nothing.\n"; |
| 468 | #endif // __BIONIC__ |
Nick Kralevich | 5bcf398 | 2013-06-28 10:34:09 -0700 | [diff] [blame] | 469 | } |
| 470 | |
Nick Kralevich | be0e43b | 2014-07-23 13:56:23 -0700 | [diff] [blame] | 471 | TEST_F(DEATHTEST, strlcpy_fortified) { |
Christopher Ferris | f04935c | 2013-12-20 18:43:21 -0800 | [diff] [blame] | 472 | #if defined(__BIONIC__) |
Nick Kralevich | 5bcf398 | 2013-06-28 10:34:09 -0700 | [diff] [blame] | 473 | ::testing::FLAGS_gtest_death_test_style = "threadsafe"; |
| 474 | char bufa[15]; |
| 475 | char bufb[10]; |
| 476 | strcpy(bufa, "01234567890123"); |
| 477 | size_t n = strlen(bufa); |
| 478 | ASSERT_EXIT(strlcpy(bufb, bufa, n), testing::KilledBySignal(SIGABRT), ""); |
Christopher Ferris | f04935c | 2013-12-20 18:43:21 -0800 | [diff] [blame] | 479 | #else // __BIONIC__ |
| 480 | GTEST_LOG_(INFO) << "This test does nothing.\n"; |
| 481 | #endif // __BIONIC__ |
Nick Kralevich | 5bcf398 | 2013-06-28 10:34:09 -0700 | [diff] [blame] | 482 | } |
| 483 | |
Nick Kralevich | be0e43b | 2014-07-23 13:56:23 -0700 | [diff] [blame] | 484 | TEST_F(DEATHTEST, strlcat_fortified) { |
Christopher Ferris | f04935c | 2013-12-20 18:43:21 -0800 | [diff] [blame] | 485 | #if defined(__BIONIC__) |
Nick Kralevich | a6cde39 | 2013-06-29 08:15:25 -0700 | [diff] [blame] | 486 | ::testing::FLAGS_gtest_death_test_style = "threadsafe"; |
| 487 | char bufa[15]; |
| 488 | char bufb[10]; |
| 489 | bufb[0] = '\0'; |
| 490 | strcpy(bufa, "01234567890123"); |
| 491 | size_t n = strlen(bufa); |
| 492 | ASSERT_EXIT(strlcat(bufb, bufa, n), testing::KilledBySignal(SIGABRT), ""); |
Christopher Ferris | f04935c | 2013-12-20 18:43:21 -0800 | [diff] [blame] | 493 | #else // __BIONIC__ |
| 494 | GTEST_LOG_(INFO) << "This test does nothing.\n"; |
| 495 | #endif // __BIONIC__ |
Nick Kralevich | a6cde39 | 2013-06-29 08:15:25 -0700 | [diff] [blame] | 496 | } |
| 497 | |
Nick Kralevich | be0e43b | 2014-07-23 13:56:23 -0700 | [diff] [blame] | 498 | TEST_F(DEATHTEST, sprintf_fortified) { |
Nick Kralevich | 5bcf398 | 2013-06-28 10:34:09 -0700 | [diff] [blame] | 499 | ::testing::FLAGS_gtest_death_test_style = "threadsafe"; |
| 500 | char buf[10]; |
| 501 | char source_buf[15]; |
| 502 | memcpy(source_buf, "12345678901234", 15); |
| 503 | ASSERT_EXIT(sprintf(buf, "%s", source_buf), testing::KilledBySignal(SIGABRT), ""); |
| 504 | } |
| 505 | |
Nick Kralevich | b91791d | 2013-10-02 14:14:40 -0700 | [diff] [blame] | 506 | #ifndef __clang__ |
| 507 | // This test is disabled in clang because clang doesn't properly detect |
| 508 | // this buffer overflow. TODO: Fix clang. |
Nick Kralevich | be0e43b | 2014-07-23 13:56:23 -0700 | [diff] [blame] | 509 | TEST_F(DEATHTEST, sprintf_malloc_fortified) { |
Nick Kralevich | b91791d | 2013-10-02 14:14:40 -0700 | [diff] [blame] | 510 | ::testing::FLAGS_gtest_death_test_style = "threadsafe"; |
| 511 | char* buf = (char *) malloc(10); |
| 512 | char source_buf[11]; |
| 513 | memcpy(source_buf, "1234567890", 11); |
| 514 | ASSERT_EXIT(sprintf(buf, "%s", source_buf), testing::KilledBySignal(SIGABRT), ""); |
| 515 | free(buf); |
| 516 | } |
| 517 | #endif |
| 518 | |
Nick Kralevich | 5bcf398 | 2013-06-28 10:34:09 -0700 | [diff] [blame] | 519 | static int vsprintf_helper(const char *fmt, ...) { |
| 520 | char buf[10]; |
| 521 | va_list va; |
| 522 | int result; |
| 523 | |
| 524 | va_start(va, fmt); |
| 525 | result = vsprintf(buf, fmt, va); // should crash here |
| 526 | va_end(va); |
| 527 | return result; |
| 528 | } |
| 529 | |
Nick Kralevich | be0e43b | 2014-07-23 13:56:23 -0700 | [diff] [blame] | 530 | TEST_F(DEATHTEST, vsprintf_fortified) { |
Nick Kralevich | 5bcf398 | 2013-06-28 10:34:09 -0700 | [diff] [blame] | 531 | ::testing::FLAGS_gtest_death_test_style = "threadsafe"; |
| 532 | ASSERT_EXIT(vsprintf_helper("%s", "0123456789"), testing::KilledBySignal(SIGABRT), ""); |
| 533 | } |
| 534 | |
Nick Kralevich | be0e43b | 2014-07-23 13:56:23 -0700 | [diff] [blame] | 535 | TEST_F(DEATHTEST, vsprintf2_fortified) { |
Nick Kralevich | 5bcf398 | 2013-06-28 10:34:09 -0700 | [diff] [blame] | 536 | ::testing::FLAGS_gtest_death_test_style = "threadsafe"; |
| 537 | ASSERT_EXIT(vsprintf_helper("0123456789"), testing::KilledBySignal(SIGABRT), ""); |
| 538 | } |
| 539 | |
| 540 | static int vsnprintf_helper(const char *fmt, ...) { |
| 541 | char buf[10]; |
| 542 | va_list va; |
| 543 | int result; |
| 544 | size_t size = atoi("11"); |
| 545 | |
| 546 | va_start(va, fmt); |
| 547 | result = vsnprintf(buf, size, fmt, va); // should crash here |
| 548 | va_end(va); |
| 549 | return result; |
| 550 | } |
| 551 | |
Nick Kralevich | be0e43b | 2014-07-23 13:56:23 -0700 | [diff] [blame] | 552 | TEST_F(DEATHTEST, vsnprintf_fortified) { |
Nick Kralevich | 5bcf398 | 2013-06-28 10:34:09 -0700 | [diff] [blame] | 553 | ::testing::FLAGS_gtest_death_test_style = "threadsafe"; |
| 554 | ASSERT_EXIT(vsnprintf_helper("%s", "0123456789"), testing::KilledBySignal(SIGABRT), ""); |
| 555 | } |
| 556 | |
Nick Kralevich | be0e43b | 2014-07-23 13:56:23 -0700 | [diff] [blame] | 557 | TEST_F(DEATHTEST, vsnprintf2_fortified) { |
Nick Kralevich | 5bcf398 | 2013-06-28 10:34:09 -0700 | [diff] [blame] | 558 | ::testing::FLAGS_gtest_death_test_style = "threadsafe"; |
| 559 | ASSERT_EXIT(vsnprintf_helper("0123456789"), testing::KilledBySignal(SIGABRT), ""); |
| 560 | } |
| 561 | |
Nick Kralevich | be0e43b | 2014-07-23 13:56:23 -0700 | [diff] [blame] | 562 | TEST_F(DEATHTEST, strncat_fortified) { |
Nick Kralevich | 5bcf398 | 2013-06-28 10:34:09 -0700 | [diff] [blame] | 563 | ::testing::FLAGS_gtest_death_test_style = "threadsafe"; |
| 564 | char buf[10]; |
| 565 | size_t n = atoi("10"); // avoid compiler optimizations |
| 566 | strncpy(buf, "012345678", n); |
| 567 | ASSERT_EXIT(strncat(buf, "9", n), testing::KilledBySignal(SIGABRT), ""); |
| 568 | } |
| 569 | |
Nick Kralevich | be0e43b | 2014-07-23 13:56:23 -0700 | [diff] [blame] | 570 | TEST_F(DEATHTEST, strncat2_fortified) { |
Nick Kralevich | 5bcf398 | 2013-06-28 10:34:09 -0700 | [diff] [blame] | 571 | ::testing::FLAGS_gtest_death_test_style = "threadsafe"; |
| 572 | char buf[10]; |
| 573 | buf[0] = '\0'; |
| 574 | size_t n = atoi("10"); // avoid compiler optimizations |
| 575 | ASSERT_EXIT(strncat(buf, "0123456789", n), testing::KilledBySignal(SIGABRT), ""); |
| 576 | } |
| 577 | |
Nick Kralevich | be0e43b | 2014-07-23 13:56:23 -0700 | [diff] [blame] | 578 | TEST_F(DEATHTEST, strcat_fortified) { |
Nick Kralevich | 5bcf398 | 2013-06-28 10:34:09 -0700 | [diff] [blame] | 579 | ::testing::FLAGS_gtest_death_test_style = "threadsafe"; |
| 580 | char src[11]; |
| 581 | strcpy(src, "0123456789"); |
| 582 | char buf[10]; |
| 583 | buf[0] = '\0'; |
| 584 | ASSERT_EXIT(strcat(buf, src), testing::KilledBySignal(SIGABRT), ""); |
| 585 | } |
| 586 | |
Nick Kralevich | be0e43b | 2014-07-23 13:56:23 -0700 | [diff] [blame] | 587 | TEST_F(DEATHTEST, memmove_fortified) { |
Nick Kralevich | 5bcf398 | 2013-06-28 10:34:09 -0700 | [diff] [blame] | 588 | ::testing::FLAGS_gtest_death_test_style = "threadsafe"; |
| 589 | char buf[20]; |
| 590 | strcpy(buf, "0123456789"); |
| 591 | size_t n = atoi("10"); |
| 592 | ASSERT_EXIT(memmove(buf + 11, buf, n), testing::KilledBySignal(SIGABRT), ""); |
| 593 | } |
| 594 | |
Nick Kralevich | be0e43b | 2014-07-23 13:56:23 -0700 | [diff] [blame] | 595 | TEST_F(DEATHTEST, memcpy_fortified) { |
Nick Kralevich | 5bcf398 | 2013-06-28 10:34:09 -0700 | [diff] [blame] | 596 | ::testing::FLAGS_gtest_death_test_style = "threadsafe"; |
| 597 | char bufa[10]; |
| 598 | char bufb[10]; |
| 599 | strcpy(bufa, "012345678"); |
| 600 | size_t n = atoi("11"); |
| 601 | ASSERT_EXIT(memcpy(bufb, bufa, n), testing::KilledBySignal(SIGABRT), ""); |
| 602 | } |
| 603 | |
Nick Kralevich | be0e43b | 2014-07-23 13:56:23 -0700 | [diff] [blame] | 604 | TEST_F(DEATHTEST, stpncpy_fortified) { |
Christopher Ferris | 950a58e | 2014-04-04 14:38:18 -0700 | [diff] [blame] | 605 | ::testing::FLAGS_gtest_death_test_style = "threadsafe"; |
| 606 | char bufa[15]; |
| 607 | char bufb[10]; |
| 608 | strcpy(bufa, "01234567890123"); |
| 609 | size_t n = strlen(bufa); |
| 610 | ASSERT_EXIT(stpncpy(bufb, bufa, n), testing::KilledBySignal(SIGABRT), ""); |
| 611 | } |
| 612 | |
Nick Kralevich | be0e43b | 2014-07-23 13:56:23 -0700 | [diff] [blame] | 613 | TEST_F(DEATHTEST, stpncpy2_fortified) { |
Christopher Ferris | 950a58e | 2014-04-04 14:38:18 -0700 | [diff] [blame] | 614 | ::testing::FLAGS_gtest_death_test_style = "threadsafe"; |
| 615 | char dest[11]; |
| 616 | char src[10]; |
| 617 | memcpy(src, "0123456789", sizeof(src)); // src is not null terminated |
| 618 | ASSERT_EXIT(stpncpy(dest, src, sizeof(dest)), testing::KilledBySignal(SIGABRT), ""); |
| 619 | } |
| 620 | |
Nick Kralevich | be0e43b | 2014-07-23 13:56:23 -0700 | [diff] [blame] | 621 | TEST_F(DEATHTEST, strncpy_fortified) { |
Nick Kralevich | 5bcf398 | 2013-06-28 10:34:09 -0700 | [diff] [blame] | 622 | ::testing::FLAGS_gtest_death_test_style = "threadsafe"; |
| 623 | char bufa[15]; |
| 624 | char bufb[10]; |
| 625 | strcpy(bufa, "01234567890123"); |
| 626 | size_t n = strlen(bufa); |
| 627 | ASSERT_EXIT(strncpy(bufb, bufa, n), testing::KilledBySignal(SIGABRT), ""); |
| 628 | } |
| 629 | |
Christopher Ferris | 950a58e | 2014-04-04 14:38:18 -0700 | [diff] [blame] | 630 | |
Nick Kralevich | be0e43b | 2014-07-23 13:56:23 -0700 | [diff] [blame] | 631 | TEST_F(DEATHTEST, strncpy2_fortified) { |
Nick Kralevich | 93501d3 | 2013-08-28 10:47:43 -0700 | [diff] [blame] | 632 | ::testing::FLAGS_gtest_death_test_style = "threadsafe"; |
| 633 | char dest[11]; |
| 634 | char src[10]; |
| 635 | memcpy(src, "0123456789", sizeof(src)); // src is not null terminated |
| 636 | ASSERT_EXIT(strncpy(dest, src, sizeof(dest)), testing::KilledBySignal(SIGABRT), ""); |
| 637 | } |
| 638 | |
Nick Kralevich | be0e43b | 2014-07-23 13:56:23 -0700 | [diff] [blame] | 639 | TEST_F(DEATHTEST, snprintf_fortified) { |
Nick Kralevich | 5bcf398 | 2013-06-28 10:34:09 -0700 | [diff] [blame] | 640 | ::testing::FLAGS_gtest_death_test_style = "threadsafe"; |
| 641 | char bufa[15]; |
| 642 | char bufb[10]; |
| 643 | strcpy(bufa, "0123456789"); |
| 644 | size_t n = strlen(bufa) + 1; |
| 645 | ASSERT_EXIT(snprintf(bufb, n, "%s", bufa), testing::KilledBySignal(SIGABRT), ""); |
| 646 | } |
| 647 | |
Nick Kralevich | be0e43b | 2014-07-23 13:56:23 -0700 | [diff] [blame] | 648 | TEST_F(DEATHTEST, bzero_fortified) { |
Nick Kralevich | a6cde39 | 2013-06-29 08:15:25 -0700 | [diff] [blame] | 649 | ::testing::FLAGS_gtest_death_test_style = "threadsafe"; |
| 650 | char buf[10]; |
| 651 | memcpy(buf, "0123456789", sizeof(buf)); |
| 652 | size_t n = atoi("11"); |
| 653 | ASSERT_EXIT(bzero(buf, n), testing::KilledBySignal(SIGABRT), ""); |
| 654 | } |
| 655 | |
Nick Kralevich | be0e43b | 2014-07-23 13:56:23 -0700 | [diff] [blame] | 656 | TEST_F(DEATHTEST, umask_fortified) { |
Nick Kralevich | a6cde39 | 2013-06-29 08:15:25 -0700 | [diff] [blame] | 657 | ::testing::FLAGS_gtest_death_test_style = "threadsafe"; |
| 658 | mode_t mask = atoi("1023"); // 01777 in octal |
| 659 | ASSERT_EXIT(umask(mask), testing::KilledBySignal(SIGABRT), ""); |
| 660 | } |
| 661 | |
Nick Kralevich | be0e43b | 2014-07-23 13:56:23 -0700 | [diff] [blame] | 662 | TEST_F(DEATHTEST, recv_fortified) { |
Nick Kralevich | 60f4f9a | 2013-09-24 16:32:07 -0700 | [diff] [blame] | 663 | ::testing::FLAGS_gtest_death_test_style = "threadsafe"; |
| 664 | size_t data_len = atoi("11"); // suppress compiler optimizations |
| 665 | char buf[10]; |
| 666 | ASSERT_EXIT(recv(0, buf, data_len, 0), testing::KilledBySignal(SIGABRT), ""); |
| 667 | } |
| 668 | |
Nick Kralevich | be0e43b | 2014-07-23 13:56:23 -0700 | [diff] [blame] | 669 | TEST_F(DEATHTEST, FD_ISSET_fortified) { |
Elliott Hughes | 063525c | 2014-05-13 11:19:57 -0700 | [diff] [blame] | 670 | #if defined(__BIONIC__) // glibc catches this at compile-time. |
Nick Kralevich | 90201d5 | 2013-10-02 16:11:30 -0700 | [diff] [blame] | 671 | ::testing::FLAGS_gtest_death_test_style = "threadsafe"; |
| 672 | fd_set set; |
| 673 | memset(&set, 0, sizeof(set)); |
| 674 | ASSERT_EXIT(FD_ISSET(-1, &set), testing::KilledBySignal(SIGABRT), ""); |
Elliott Hughes | 409588c | 2014-04-23 23:02:43 -0700 | [diff] [blame] | 675 | #endif |
Nick Kralevich | 90201d5 | 2013-10-02 16:11:30 -0700 | [diff] [blame] | 676 | } |
| 677 | |
Nick Kralevich | be0e43b | 2014-07-23 13:56:23 -0700 | [diff] [blame] | 678 | TEST_F(DEATHTEST, FD_ISSET_2_fortified) { |
Nick Kralevich | 7943df6 | 2013-10-03 14:08:39 -0700 | [diff] [blame] | 679 | ::testing::FLAGS_gtest_death_test_style = "threadsafe"; |
| 680 | char buf[1]; |
| 681 | fd_set* set = (fd_set*) buf; |
| 682 | ASSERT_EXIT(FD_ISSET(0, set), testing::KilledBySignal(SIGABRT), ""); |
| 683 | } |
| 684 | |
Nick Kralevich | be0e43b | 2014-07-23 13:56:23 -0700 | [diff] [blame] | 685 | TEST_F(DEATHTEST, read_fortified) { |
Nick Kralevich | b036b5c | 2013-10-09 20:16:34 -0700 | [diff] [blame] | 686 | ::testing::FLAGS_gtest_death_test_style = "threadsafe"; |
| 687 | char buf[1]; |
| 688 | size_t ct = atoi("2"); // prevent optimizations |
| 689 | int fd = open("/dev/null", O_RDONLY); |
| 690 | ASSERT_EXIT(read(fd, buf, ct), testing::KilledBySignal(SIGABRT), ""); |
| 691 | close(fd); |
| 692 | } |
| 693 | |
Nick Kralevich | 5bcf398 | 2013-06-28 10:34:09 -0700 | [diff] [blame] | 694 | extern "C" char* __strncat_chk(char*, const char*, size_t, size_t); |
| 695 | extern "C" char* __strcat_chk(char*, const char*, size_t); |
| 696 | |
| 697 | TEST(TEST_NAME, strncat) { |
| 698 | char buf[10]; |
| 699 | memset(buf, 'A', sizeof(buf)); |
| 700 | buf[0] = 'a'; |
| 701 | buf[1] = '\0'; |
| 702 | char* res = __strncat_chk(buf, "01234", sizeof(buf) - strlen(buf) - 1, sizeof(buf)); |
| 703 | ASSERT_EQ(buf, res); |
| 704 | ASSERT_EQ('a', buf[0]); |
| 705 | ASSERT_EQ('0', buf[1]); |
| 706 | ASSERT_EQ('1', buf[2]); |
| 707 | ASSERT_EQ('2', buf[3]); |
| 708 | ASSERT_EQ('3', buf[4]); |
| 709 | ASSERT_EQ('4', buf[5]); |
| 710 | ASSERT_EQ('\0', buf[6]); |
| 711 | ASSERT_EQ('A', buf[7]); |
| 712 | ASSERT_EQ('A', buf[8]); |
| 713 | ASSERT_EQ('A', buf[9]); |
| 714 | } |
| 715 | |
| 716 | TEST(TEST_NAME, strncat2) { |
| 717 | char buf[10]; |
| 718 | memset(buf, 'A', sizeof(buf)); |
| 719 | buf[0] = 'a'; |
| 720 | buf[1] = '\0'; |
| 721 | char* res = __strncat_chk(buf, "0123456789", 5, sizeof(buf)); |
| 722 | ASSERT_EQ(buf, res); |
| 723 | ASSERT_EQ('a', buf[0]); |
| 724 | ASSERT_EQ('0', buf[1]); |
| 725 | ASSERT_EQ('1', buf[2]); |
| 726 | ASSERT_EQ('2', buf[3]); |
| 727 | ASSERT_EQ('3', buf[4]); |
| 728 | ASSERT_EQ('4', buf[5]); |
| 729 | ASSERT_EQ('\0', buf[6]); |
| 730 | ASSERT_EQ('A', buf[7]); |
| 731 | ASSERT_EQ('A', buf[8]); |
| 732 | ASSERT_EQ('A', buf[9]); |
| 733 | } |
| 734 | |
| 735 | TEST(TEST_NAME, strncat3) { |
| 736 | char buf[10]; |
| 737 | memset(buf, 'A', sizeof(buf)); |
| 738 | buf[0] = '\0'; |
| 739 | char* res = __strncat_chk(buf, "0123456789", 5, sizeof(buf)); |
| 740 | ASSERT_EQ(buf, res); |
| 741 | ASSERT_EQ('0', buf[0]); |
| 742 | ASSERT_EQ('1', buf[1]); |
| 743 | ASSERT_EQ('2', buf[2]); |
| 744 | ASSERT_EQ('3', buf[3]); |
| 745 | ASSERT_EQ('4', buf[4]); |
| 746 | ASSERT_EQ('\0', buf[5]); |
| 747 | ASSERT_EQ('A', buf[6]); |
| 748 | ASSERT_EQ('A', buf[7]); |
| 749 | ASSERT_EQ('A', buf[8]); |
| 750 | ASSERT_EQ('A', buf[9]); |
| 751 | } |
| 752 | |
| 753 | TEST(TEST_NAME, strncat4) { |
| 754 | char buf[10]; |
| 755 | memset(buf, 'A', sizeof(buf)); |
| 756 | buf[9] = '\0'; |
| 757 | char* res = __strncat_chk(buf, "", 5, sizeof(buf)); |
| 758 | ASSERT_EQ(buf, res); |
| 759 | ASSERT_EQ('A', buf[0]); |
| 760 | ASSERT_EQ('A', buf[1]); |
| 761 | ASSERT_EQ('A', buf[2]); |
| 762 | ASSERT_EQ('A', buf[3]); |
| 763 | ASSERT_EQ('A', buf[4]); |
| 764 | ASSERT_EQ('A', buf[5]); |
| 765 | ASSERT_EQ('A', buf[6]); |
| 766 | ASSERT_EQ('A', buf[7]); |
| 767 | ASSERT_EQ('A', buf[8]); |
| 768 | ASSERT_EQ('\0', buf[9]); |
| 769 | } |
| 770 | |
| 771 | TEST(TEST_NAME, strncat5) { |
| 772 | char buf[10]; |
| 773 | memset(buf, 'A', sizeof(buf)); |
| 774 | buf[0] = 'a'; |
| 775 | buf[1] = '\0'; |
| 776 | char* res = __strncat_chk(buf, "01234567", 8, sizeof(buf)); |
| 777 | ASSERT_EQ(buf, res); |
| 778 | ASSERT_EQ('a', buf[0]); |
| 779 | ASSERT_EQ('0', buf[1]); |
| 780 | ASSERT_EQ('1', buf[2]); |
| 781 | ASSERT_EQ('2', buf[3]); |
| 782 | ASSERT_EQ('3', buf[4]); |
| 783 | ASSERT_EQ('4', buf[5]); |
| 784 | ASSERT_EQ('5', buf[6]); |
| 785 | ASSERT_EQ('6', buf[7]); |
| 786 | ASSERT_EQ('7', buf[8]); |
| 787 | ASSERT_EQ('\0', buf[9]); |
| 788 | } |
| 789 | |
| 790 | TEST(TEST_NAME, strncat6) { |
| 791 | char buf[10]; |
| 792 | memset(buf, 'A', sizeof(buf)); |
| 793 | buf[0] = 'a'; |
| 794 | buf[1] = '\0'; |
| 795 | char* res = __strncat_chk(buf, "01234567", 9, sizeof(buf)); |
| 796 | ASSERT_EQ(buf, res); |
| 797 | ASSERT_EQ('a', buf[0]); |
| 798 | ASSERT_EQ('0', buf[1]); |
| 799 | ASSERT_EQ('1', buf[2]); |
| 800 | ASSERT_EQ('2', buf[3]); |
| 801 | ASSERT_EQ('3', buf[4]); |
| 802 | ASSERT_EQ('4', buf[5]); |
| 803 | ASSERT_EQ('5', buf[6]); |
| 804 | ASSERT_EQ('6', buf[7]); |
| 805 | ASSERT_EQ('7', buf[8]); |
| 806 | ASSERT_EQ('\0', buf[9]); |
| 807 | } |
| 808 | |
| 809 | |
| 810 | TEST(TEST_NAME, strcat) { |
| 811 | char buf[10]; |
| 812 | memset(buf, 'A', sizeof(buf)); |
| 813 | buf[0] = 'a'; |
| 814 | buf[1] = '\0'; |
| 815 | char* res = __strcat_chk(buf, "01234", sizeof(buf)); |
| 816 | ASSERT_EQ(buf, res); |
| 817 | ASSERT_EQ('a', buf[0]); |
| 818 | ASSERT_EQ('0', buf[1]); |
| 819 | ASSERT_EQ('1', buf[2]); |
| 820 | ASSERT_EQ('2', buf[3]); |
| 821 | ASSERT_EQ('3', buf[4]); |
| 822 | ASSERT_EQ('4', buf[5]); |
| 823 | ASSERT_EQ('\0', buf[6]); |
| 824 | ASSERT_EQ('A', buf[7]); |
| 825 | ASSERT_EQ('A', buf[8]); |
| 826 | ASSERT_EQ('A', buf[9]); |
| 827 | } |
| 828 | |
| 829 | TEST(TEST_NAME, strcat2) { |
| 830 | char buf[10]; |
| 831 | memset(buf, 'A', sizeof(buf)); |
| 832 | buf[0] = 'a'; |
| 833 | buf[1] = '\0'; |
| 834 | char* res = __strcat_chk(buf, "01234567", sizeof(buf)); |
| 835 | ASSERT_EQ(buf, res); |
| 836 | ASSERT_EQ('a', buf[0]); |
| 837 | ASSERT_EQ('0', buf[1]); |
| 838 | ASSERT_EQ('1', buf[2]); |
| 839 | ASSERT_EQ('2', buf[3]); |
| 840 | ASSERT_EQ('3', buf[4]); |
| 841 | ASSERT_EQ('4', buf[5]); |
| 842 | ASSERT_EQ('5', buf[6]); |
| 843 | ASSERT_EQ('6', buf[7]); |
| 844 | ASSERT_EQ('7', buf[8]); |
| 845 | ASSERT_EQ('\0', buf[9]); |
| 846 | } |
Nick Kralevich | 93501d3 | 2013-08-28 10:47:43 -0700 | [diff] [blame] | 847 | |
Christopher Ferris | 950a58e | 2014-04-04 14:38:18 -0700 | [diff] [blame] | 848 | TEST(TEST_NAME, stpncpy) { |
| 849 | char src[10]; |
| 850 | char dst[10]; |
| 851 | memcpy(src, "0123456789", sizeof(src)); // non null terminated string |
| 852 | stpncpy(dst, src, sizeof(dst)); |
| 853 | ASSERT_EQ('0', dst[0]); |
| 854 | ASSERT_EQ('1', dst[1]); |
| 855 | ASSERT_EQ('2', dst[2]); |
| 856 | ASSERT_EQ('3', dst[3]); |
| 857 | ASSERT_EQ('4', dst[4]); |
| 858 | ASSERT_EQ('5', dst[5]); |
| 859 | ASSERT_EQ('6', dst[6]); |
| 860 | ASSERT_EQ('7', dst[7]); |
| 861 | ASSERT_EQ('8', dst[8]); |
| 862 | ASSERT_EQ('9', dst[9]); |
| 863 | } |
| 864 | |
| 865 | TEST(TEST_NAME, stpncpy2) { |
| 866 | char src[10]; |
| 867 | char dst[15]; |
| 868 | memcpy(src, "012345678\0", sizeof(src)); |
| 869 | stpncpy(dst, src, sizeof(dst)); |
| 870 | ASSERT_EQ('0', dst[0]); |
| 871 | ASSERT_EQ('1', dst[1]); |
| 872 | ASSERT_EQ('2', dst[2]); |
| 873 | ASSERT_EQ('3', dst[3]); |
| 874 | ASSERT_EQ('4', dst[4]); |
| 875 | ASSERT_EQ('5', dst[5]); |
| 876 | ASSERT_EQ('6', dst[6]); |
| 877 | ASSERT_EQ('7', dst[7]); |
| 878 | ASSERT_EQ('8', dst[8]); |
| 879 | ASSERT_EQ('\0', dst[9]); |
| 880 | ASSERT_EQ('\0', dst[10]); |
| 881 | ASSERT_EQ('\0', dst[11]); |
| 882 | ASSERT_EQ('\0', dst[12]); |
| 883 | ASSERT_EQ('\0', dst[13]); |
| 884 | ASSERT_EQ('\0', dst[14]); |
| 885 | } |
| 886 | |
Nick Kralevich | 93501d3 | 2013-08-28 10:47:43 -0700 | [diff] [blame] | 887 | TEST(TEST_NAME, strncpy) { |
| 888 | char src[10]; |
| 889 | char dst[10]; |
| 890 | memcpy(src, "0123456789", sizeof(src)); // non null terminated string |
| 891 | strncpy(dst, src, sizeof(dst)); |
| 892 | ASSERT_EQ('0', dst[0]); |
| 893 | ASSERT_EQ('1', dst[1]); |
| 894 | ASSERT_EQ('2', dst[2]); |
| 895 | ASSERT_EQ('3', dst[3]); |
| 896 | ASSERT_EQ('4', dst[4]); |
| 897 | ASSERT_EQ('5', dst[5]); |
| 898 | ASSERT_EQ('6', dst[6]); |
| 899 | ASSERT_EQ('7', dst[7]); |
| 900 | ASSERT_EQ('8', dst[8]); |
| 901 | ASSERT_EQ('9', dst[9]); |
| 902 | } |
| 903 | |
| 904 | TEST(TEST_NAME, strncpy2) { |
| 905 | char src[10]; |
| 906 | char dst[15]; |
| 907 | memcpy(src, "012345678\0", sizeof(src)); |
| 908 | strncpy(dst, src, sizeof(dst)); |
| 909 | ASSERT_EQ('0', dst[0]); |
| 910 | ASSERT_EQ('1', dst[1]); |
| 911 | ASSERT_EQ('2', dst[2]); |
| 912 | ASSERT_EQ('3', dst[3]); |
| 913 | ASSERT_EQ('4', dst[4]); |
| 914 | ASSERT_EQ('5', dst[5]); |
| 915 | ASSERT_EQ('6', dst[6]); |
| 916 | ASSERT_EQ('7', dst[7]); |
| 917 | ASSERT_EQ('8', dst[8]); |
| 918 | ASSERT_EQ('\0', dst[9]); |
| 919 | ASSERT_EQ('\0', dst[10]); |
| 920 | ASSERT_EQ('\0', dst[11]); |
| 921 | ASSERT_EQ('\0', dst[12]); |
| 922 | ASSERT_EQ('\0', dst[13]); |
| 923 | ASSERT_EQ('\0', dst[14]); |
| 924 | } |
Christopher Ferris | 16e185c | 2013-09-10 16:56:34 -0700 | [diff] [blame] | 925 | |
| 926 | TEST(TEST_NAME, strcat_chk_max_int_size) { |
| 927 | char buf[10]; |
| 928 | memset(buf, 'A', sizeof(buf)); |
| 929 | buf[0] = 'a'; |
| 930 | buf[1] = '\0'; |
| 931 | char* res = __strcat_chk(buf, "01234567", (size_t)-1); |
| 932 | ASSERT_EQ(buf, res); |
| 933 | ASSERT_EQ('a', buf[0]); |
| 934 | ASSERT_EQ('0', buf[1]); |
| 935 | ASSERT_EQ('1', buf[2]); |
| 936 | ASSERT_EQ('2', buf[3]); |
| 937 | ASSERT_EQ('3', buf[4]); |
| 938 | ASSERT_EQ('4', buf[5]); |
| 939 | ASSERT_EQ('5', buf[6]); |
| 940 | ASSERT_EQ('6', buf[7]); |
| 941 | ASSERT_EQ('7', buf[8]); |
| 942 | ASSERT_EQ('\0', buf[9]); |
| 943 | } |
| 944 | |
Christopher Ferris | 950a58e | 2014-04-04 14:38:18 -0700 | [diff] [blame] | 945 | extern "C" char* __stpcpy_chk(char*, const char*, size_t); |
| 946 | |
| 947 | TEST(TEST_NAME, stpcpy_chk_max_int_size) { |
| 948 | char buf[10]; |
| 949 | char* res = __stpcpy_chk(buf, "012345678", (size_t)-1); |
| 950 | ASSERT_EQ(buf + strlen("012345678"), res); |
| 951 | ASSERT_STREQ("012345678", buf); |
| 952 | } |
| 953 | |
Christopher Ferris | 16e185c | 2013-09-10 16:56:34 -0700 | [diff] [blame] | 954 | extern "C" char* __strcpy_chk(char*, const char*, size_t); |
| 955 | |
| 956 | TEST(TEST_NAME, strcpy_chk_max_int_size) { |
| 957 | char buf[10]; |
| 958 | char* res = __strcpy_chk(buf, "012345678", (size_t)-1); |
| 959 | ASSERT_EQ(buf, res); |
Christopher Ferris | 950a58e | 2014-04-04 14:38:18 -0700 | [diff] [blame] | 960 | ASSERT_STREQ("012345678", buf); |
Christopher Ferris | 16e185c | 2013-09-10 16:56:34 -0700 | [diff] [blame] | 961 | } |
| 962 | |
| 963 | extern "C" void* __memcpy_chk(void*, const void*, size_t, size_t); |
| 964 | |
| 965 | TEST(TEST_NAME, memcpy_chk_max_int_size) { |
| 966 | char buf[10]; |
| 967 | void* res = __memcpy_chk(buf, "012345678", sizeof(buf), (size_t)-1); |
| 968 | ASSERT_EQ((void*)buf, res); |
| 969 | ASSERT_EQ('0', buf[0]); |
| 970 | ASSERT_EQ('1', buf[1]); |
| 971 | ASSERT_EQ('2', buf[2]); |
| 972 | ASSERT_EQ('3', buf[3]); |
| 973 | ASSERT_EQ('4', buf[4]); |
| 974 | ASSERT_EQ('5', buf[5]); |
| 975 | ASSERT_EQ('6', buf[6]); |
| 976 | ASSERT_EQ('7', buf[7]); |
| 977 | ASSERT_EQ('8', buf[8]); |
| 978 | ASSERT_EQ('\0', buf[9]); |
| 979 | } |
Stephen Hines | 6e38072 | 2013-10-11 00:45:24 -0700 | [diff] [blame] | 980 | |
| 981 | // Verify that macro expansion is done properly for sprintf/snprintf (which |
| 982 | // are defined as macros in stdio.h under clang). |
| 983 | #define CONTENTS "macro expansion" |
| 984 | #define BUF_AND_SIZE(A) A, sizeof(A) |
| 985 | #define BUF_AND_CONTENTS(A) A, CONTENTS |
| 986 | #define BUF_AND_SIZE_AND_CONTENTS(A) A, sizeof(A), CONTENTS |
| 987 | TEST(TEST_NAME, s_n_printf_macro_expansion) { |
| 988 | char buf[BUFSIZ]; |
| 989 | snprintf(BUF_AND_SIZE(buf), CONTENTS); |
| 990 | EXPECT_STREQ(CONTENTS, buf); |
| 991 | |
| 992 | snprintf(BUF_AND_SIZE_AND_CONTENTS(buf)); |
| 993 | EXPECT_STREQ(CONTENTS, buf); |
| 994 | |
| 995 | sprintf(BUF_AND_CONTENTS(buf)); |
| 996 | EXPECT_STREQ(CONTENTS, buf); |
| 997 | } |