Nick Kralevich | 1aae9bd | 2013-04-29 14:07:06 -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 | #undef _FORTIFY_SOURCE |
| 18 | #define _FORTIFY_SOURCE 2 |
| 19 | |
| 20 | #include <gtest/gtest.h> |
| 21 | #include <string.h> |
| 22 | |
| 23 | struct foo { |
Nick Kralevich | 13476de | 2013-06-03 10:58:06 -0700 | [diff] [blame] | 24 | char empty[0]; |
| 25 | char one[1]; |
Nick Kralevich | 1aae9bd | 2013-04-29 14:07:06 -0700 | [diff] [blame] | 26 | char a[10]; |
| 27 | char b[10]; |
| 28 | }; |
| 29 | |
| 30 | // We have to say "DeathTest" here so gtest knows to run this test (which exits) |
| 31 | // in its own process. |
Nick Kralevich | 78d6d98 | 2013-04-29 16:29:37 -0700 | [diff] [blame] | 32 | TEST(Fortify2_DeathTest, strncpy_fortified2) { |
Nick Kralevich | 1aae9bd | 2013-04-29 14:07:06 -0700 | [diff] [blame] | 33 | ::testing::FLAGS_gtest_death_test_style = "threadsafe"; |
| 34 | foo myfoo; |
| 35 | int copy_amt = atoi("11"); |
| 36 | ASSERT_EXIT(strncpy(myfoo.a, "01234567890", copy_amt), |
Nick Kralevich | fd0325b | 2013-06-11 15:45:23 -0700 | [diff] [blame] | 37 | testing::KilledBySignal(SIGABRT), ""); |
Nick Kralevich | 1aae9bd | 2013-04-29 14:07:06 -0700 | [diff] [blame] | 38 | } |
| 39 | |
Nick Kralevich | 78d6d98 | 2013-04-29 16:29:37 -0700 | [diff] [blame] | 40 | TEST(Fortify2_DeathTest, sprintf_fortified2) { |
| 41 | ::testing::FLAGS_gtest_death_test_style = "threadsafe"; |
| 42 | foo myfoo; |
| 43 | char source_buf[15]; |
| 44 | memcpy(source_buf, "12345678901234", 15); |
| 45 | ASSERT_EXIT(sprintf(myfoo.a, "%s", source_buf), |
Nick Kralevich | fd0325b | 2013-06-11 15:45:23 -0700 | [diff] [blame] | 46 | testing::KilledBySignal(SIGABRT), ""); |
Nick Kralevich | 78d6d98 | 2013-04-29 16:29:37 -0700 | [diff] [blame] | 47 | } |
| 48 | |
Nick Kralevich | c6eb985 | 2013-06-24 11:44:00 -0700 | [diff] [blame] | 49 | TEST(Fortify2_DeathTest, sprintf2_fortified2) { |
| 50 | ::testing::FLAGS_gtest_death_test_style = "threadsafe"; |
| 51 | foo myfoo; |
| 52 | ASSERT_EXIT(sprintf(myfoo.a, "0123456789"), |
| 53 | testing::KilledBySignal(SIGABRT), ""); |
| 54 | } |
| 55 | |
Nick Kralevich | 8054192 | 2013-05-01 14:55:33 -0700 | [diff] [blame] | 56 | #if __BIONIC__ |
Nick Kralevich | 13476de | 2013-06-03 10:58:06 -0700 | [diff] [blame] | 57 | // zero sized target with "\0" source (should fail) |
| 58 | TEST(Fortify2_DeathTest, strcpy_fortified2) { |
| 59 | ::testing::FLAGS_gtest_death_test_style = "threadsafe"; |
| 60 | foo myfoo; |
| 61 | char* src = strdup(""); |
| 62 | ASSERT_EXIT(strcpy(myfoo.empty, src), |
Nick Kralevich | fd0325b | 2013-06-11 15:45:23 -0700 | [diff] [blame] | 63 | testing::KilledBySignal(SIGABRT), ""); |
Nick Kralevich | 13476de | 2013-06-03 10:58:06 -0700 | [diff] [blame] | 64 | free(src); |
| 65 | } |
| 66 | |
| 67 | // zero sized target with longer source (should fail) |
| 68 | TEST(Fortify2_DeathTest, strcpy2_fortified2) { |
| 69 | ::testing::FLAGS_gtest_death_test_style = "threadsafe"; |
| 70 | foo myfoo; |
| 71 | char* src = strdup("1"); |
| 72 | ASSERT_EXIT(strcpy(myfoo.empty, src), |
Nick Kralevich | fd0325b | 2013-06-11 15:45:23 -0700 | [diff] [blame] | 73 | testing::KilledBySignal(SIGABRT), ""); |
Nick Kralevich | 13476de | 2013-06-03 10:58:06 -0700 | [diff] [blame] | 74 | free(src); |
| 75 | } |
| 76 | |
| 77 | // one byte target with longer source (should fail) |
| 78 | TEST(Fortify2_DeathTest, strcpy3_fortified2) { |
| 79 | ::testing::FLAGS_gtest_death_test_style = "threadsafe"; |
| 80 | foo myfoo; |
| 81 | char* src = strdup("12"); |
| 82 | ASSERT_EXIT(strcpy(myfoo.one, src), |
Nick Kralevich | fd0325b | 2013-06-11 15:45:23 -0700 | [diff] [blame] | 83 | testing::KilledBySignal(SIGABRT), ""); |
Nick Kralevich | 13476de | 2013-06-03 10:58:06 -0700 | [diff] [blame] | 84 | free(src); |
| 85 | } |
| 86 | |
Nick Kralevich | 4f40e51 | 2013-04-19 16:54:22 -0700 | [diff] [blame] | 87 | TEST(Fortify2_DeathTest, strchr_fortified2) { |
| 88 | ::testing::FLAGS_gtest_death_test_style = "threadsafe"; |
| 89 | foo myfoo; |
| 90 | memcpy(myfoo.a, "0123456789", sizeof(myfoo.a)); |
| 91 | myfoo.b[0] = '\0'; |
| 92 | ASSERT_EXIT(printf("%s", strchr(myfoo.a, 'a')), |
Nick Kralevich | fd0325b | 2013-06-11 15:45:23 -0700 | [diff] [blame] | 93 | testing::KilledBySignal(SIGABRT), ""); |
Nick Kralevich | 4f40e51 | 2013-04-19 16:54:22 -0700 | [diff] [blame] | 94 | } |
| 95 | |
Nick Kralevich | 277226b | 2013-05-01 15:05:01 -0700 | [diff] [blame] | 96 | TEST(Fortify2_DeathTest, strrchr_fortified2) { |
Nick Kralevich | 8054192 | 2013-05-01 14:55:33 -0700 | [diff] [blame] | 97 | ::testing::FLAGS_gtest_death_test_style = "threadsafe"; |
| 98 | foo myfoo; |
| 99 | memcpy(myfoo.a, "0123456789", 10); |
| 100 | memcpy(myfoo.b, "01234", 6); |
| 101 | ASSERT_EXIT(printf("%s", strrchr(myfoo.a, 'a')), |
Nick Kralevich | fd0325b | 2013-06-11 15:45:23 -0700 | [diff] [blame] | 102 | testing::KilledBySignal(SIGABRT), ""); |
Nick Kralevich | 8054192 | 2013-05-01 14:55:33 -0700 | [diff] [blame] | 103 | } |
Nick Kralevich | 8bafa74 | 2013-06-20 12:17:44 -0700 | [diff] [blame] | 104 | |
| 105 | TEST(Fortify2_DeathTest, strlcpy_fortified2) { |
| 106 | ::testing::FLAGS_gtest_death_test_style = "threadsafe"; |
| 107 | foo myfoo; |
| 108 | strcpy(myfoo.a, "01"); |
| 109 | size_t n = strlen(myfoo.a); |
| 110 | ASSERT_EXIT(strlcpy(myfoo.one, myfoo.a, n), |
| 111 | testing::KilledBySignal(SIGABRT), ""); |
| 112 | } |
| 113 | |
Nick Kralevich | 8054192 | 2013-05-01 14:55:33 -0700 | [diff] [blame] | 114 | #endif |
| 115 | |
Nick Kralevich | 8cc145e | 2013-05-30 13:21:14 -0700 | [diff] [blame] | 116 | TEST(Fortify2_DeathTest, strncat_fortified2) { |
| 117 | ::testing::FLAGS_gtest_death_test_style = "threadsafe"; |
| 118 | foo myfoo; |
| 119 | size_t n = atoi("10"); // avoid compiler optimizations |
| 120 | strncpy(myfoo.a, "012345678", n); |
Nick Kralevich | fd0325b | 2013-06-11 15:45:23 -0700 | [diff] [blame] | 121 | ASSERT_EXIT(strncat(myfoo.a, "9", n), testing::KilledBySignal(SIGABRT), ""); |
Nick Kralevich | 8cc145e | 2013-05-30 13:21:14 -0700 | [diff] [blame] | 122 | } |
| 123 | |
| 124 | TEST(Fortify2_DeathTest, strncat2_fortified2) { |
| 125 | ::testing::FLAGS_gtest_death_test_style = "threadsafe"; |
| 126 | foo myfoo; |
| 127 | myfoo.a[0] = '\0'; |
| 128 | size_t n = atoi("10"); // avoid compiler optimizations |
Nick Kralevich | fd0325b | 2013-06-11 15:45:23 -0700 | [diff] [blame] | 129 | ASSERT_EXIT(strncat(myfoo.a, "0123456789", n), testing::KilledBySignal(SIGABRT), ""); |
Nick Kralevich | 8cc145e | 2013-05-30 13:21:14 -0700 | [diff] [blame] | 130 | } |
| 131 | |
Nick Kralevich | cf87019 | 2013-05-30 16:48:53 -0700 | [diff] [blame] | 132 | TEST(Fortify2_DeathTest, strncat3_fortified2) { |
| 133 | ::testing::FLAGS_gtest_death_test_style = "threadsafe"; |
| 134 | foo myfoo; |
| 135 | memcpy(myfoo.a, "0123456789", sizeof(myfoo.a)); // unterminated string |
| 136 | myfoo.b[0] = '\0'; |
| 137 | size_t n = atoi("10"); // avoid compiler optimizations |
Nick Kralevich | fd0325b | 2013-06-11 15:45:23 -0700 | [diff] [blame] | 138 | ASSERT_EXIT(strncat(myfoo.b, myfoo.a, n), testing::KilledBySignal(SIGABRT), ""); |
Nick Kralevich | cf87019 | 2013-05-30 16:48:53 -0700 | [diff] [blame] | 139 | } |
| 140 | |
| 141 | TEST(Fortify2_DeathTest, strcat_fortified2) { |
| 142 | ::testing::FLAGS_gtest_death_test_style = "threadsafe"; |
| 143 | char src[11]; |
| 144 | strcpy(src, "0123456789"); |
| 145 | foo myfoo; |
| 146 | myfoo.a[0] = '\0'; |
Nick Kralevich | fd0325b | 2013-06-11 15:45:23 -0700 | [diff] [blame] | 147 | ASSERT_EXIT(strcat(myfoo.a, src), testing::KilledBySignal(SIGABRT), ""); |
Nick Kralevich | cf87019 | 2013-05-30 16:48:53 -0700 | [diff] [blame] | 148 | } |
| 149 | |
| 150 | TEST(Fortify2_DeathTest, strcat2_fortified2) { |
| 151 | ::testing::FLAGS_gtest_death_test_style = "threadsafe"; |
| 152 | foo myfoo; |
| 153 | memcpy(myfoo.a, "0123456789", sizeof(myfoo.a)); // unterminated string |
| 154 | myfoo.b[0] = '\0'; |
Nick Kralevich | fd0325b | 2013-06-11 15:45:23 -0700 | [diff] [blame] | 155 | ASSERT_EXIT(strcat(myfoo.b, myfoo.a), testing::KilledBySignal(SIGABRT), ""); |
Nick Kralevich | cf87019 | 2013-05-30 16:48:53 -0700 | [diff] [blame] | 156 | } |
| 157 | |
Nick Kralevich | 621b19d | 2013-06-25 10:02:35 -0700 | [diff] [blame] | 158 | TEST(Fortify2_DeathTest, snprintf_fortified2) { |
| 159 | ::testing::FLAGS_gtest_death_test_style = "threadsafe"; |
| 160 | foo myfoo; |
| 161 | strcpy(myfoo.a, "012345678"); |
| 162 | size_t n = strlen(myfoo.a) + 2; |
| 163 | ASSERT_EXIT(snprintf(myfoo.b, n, "a%s", myfoo.a), testing::KilledBySignal(SIGABRT), ""); |
| 164 | } |
| 165 | |
Nick Kralevich | 78d6d98 | 2013-04-29 16:29:37 -0700 | [diff] [blame] | 166 | /***********************************************************/ |
| 167 | /* TESTS BELOW HERE DUPLICATE TESTS FROM fortify1_test.cpp */ |
| 168 | /***********************************************************/ |
| 169 | |
Nick Kralevich | 1aae9bd | 2013-04-29 14:07:06 -0700 | [diff] [blame] | 170 | #if __BIONIC__ |
Nick Kralevich | 13476de | 2013-06-03 10:58:06 -0700 | [diff] [blame] | 171 | // multibyte target where we over fill (should fail) |
Nick Kralevich | 1aae9bd | 2013-04-29 14:07:06 -0700 | [diff] [blame] | 172 | TEST(Fortify2_DeathTest, strcpy_fortified) { |
| 173 | ::testing::FLAGS_gtest_death_test_style = "threadsafe"; |
| 174 | char buf[10]; |
| 175 | char *orig = strdup("0123456789"); |
Nick Kralevich | fd0325b | 2013-06-11 15:45:23 -0700 | [diff] [blame] | 176 | ASSERT_EXIT(strcpy(buf, orig), testing::KilledBySignal(SIGABRT), ""); |
Nick Kralevich | 1aae9bd | 2013-04-29 14:07:06 -0700 | [diff] [blame] | 177 | free(orig); |
| 178 | } |
| 179 | |
Nick Kralevich | 13476de | 2013-06-03 10:58:06 -0700 | [diff] [blame] | 180 | // zero sized target with "\0" source (should fail) |
| 181 | TEST(Fortify2_DeathTest, strcpy2_fortified) { |
| 182 | ::testing::FLAGS_gtest_death_test_style = "threadsafe"; |
| 183 | char buf[0]; |
| 184 | char *orig = strdup(""); |
Nick Kralevich | fd0325b | 2013-06-11 15:45:23 -0700 | [diff] [blame] | 185 | ASSERT_EXIT(strcpy(buf, orig), testing::KilledBySignal(SIGABRT), ""); |
Nick Kralevich | 13476de | 2013-06-03 10:58:06 -0700 | [diff] [blame] | 186 | free(orig); |
| 187 | } |
| 188 | |
| 189 | // zero sized target with longer source (should fail) |
| 190 | TEST(Fortify2_DeathTest, strcpy3_fortified) { |
| 191 | ::testing::FLAGS_gtest_death_test_style = "threadsafe"; |
| 192 | char buf[0]; |
| 193 | char *orig = strdup("1"); |
Nick Kralevich | fd0325b | 2013-06-11 15:45:23 -0700 | [diff] [blame] | 194 | ASSERT_EXIT(strcpy(buf, orig), testing::KilledBySignal(SIGABRT), ""); |
Nick Kralevich | 13476de | 2013-06-03 10:58:06 -0700 | [diff] [blame] | 195 | free(orig); |
| 196 | } |
| 197 | |
| 198 | // one byte target with longer source (should fail) |
| 199 | TEST(Fortify2_DeathTest, strcpy4_fortified) { |
| 200 | ::testing::FLAGS_gtest_death_test_style = "threadsafe"; |
| 201 | char buf[1]; |
| 202 | char *orig = strdup("12"); |
Nick Kralevich | fd0325b | 2013-06-11 15:45:23 -0700 | [diff] [blame] | 203 | ASSERT_EXIT(strcpy(buf, orig), testing::KilledBySignal(SIGABRT), ""); |
Nick Kralevich | 13476de | 2013-06-03 10:58:06 -0700 | [diff] [blame] | 204 | free(orig); |
| 205 | } |
| 206 | |
Nick Kralevich | 1aae9bd | 2013-04-29 14:07:06 -0700 | [diff] [blame] | 207 | TEST(Fortify2_DeathTest, strlen_fortified) { |
| 208 | ::testing::FLAGS_gtest_death_test_style = "threadsafe"; |
| 209 | char buf[10]; |
| 210 | memcpy(buf, "0123456789", sizeof(buf)); |
Nick Kralevich | fd0325b | 2013-06-11 15:45:23 -0700 | [diff] [blame] | 211 | ASSERT_EXIT(printf("%d", strlen(buf)), testing::KilledBySignal(SIGABRT), ""); |
Nick Kralevich | 1aae9bd | 2013-04-29 14:07:06 -0700 | [diff] [blame] | 212 | } |
| 213 | |
| 214 | TEST(Fortify2_DeathTest, strchr_fortified) { |
| 215 | ::testing::FLAGS_gtest_death_test_style = "threadsafe"; |
| 216 | char buf[10]; |
| 217 | memcpy(buf, "0123456789", sizeof(buf)); |
Nick Kralevich | fd0325b | 2013-06-11 15:45:23 -0700 | [diff] [blame] | 218 | ASSERT_EXIT(printf("%s", strchr(buf, 'a')), testing::KilledBySignal(SIGABRT), ""); |
Nick Kralevich | 1aae9bd | 2013-04-29 14:07:06 -0700 | [diff] [blame] | 219 | } |
| 220 | |
| 221 | TEST(Fortify2_DeathTest, strrchr_fortified) { |
| 222 | ::testing::FLAGS_gtest_death_test_style = "threadsafe"; |
| 223 | char buf[10]; |
| 224 | memcpy(buf, "0123456789", sizeof(buf)); |
Nick Kralevich | fd0325b | 2013-06-11 15:45:23 -0700 | [diff] [blame] | 225 | ASSERT_EXIT(printf("%s", strrchr(buf, 'a')), testing::KilledBySignal(SIGABRT), ""); |
Nick Kralevich | 1aae9bd | 2013-04-29 14:07:06 -0700 | [diff] [blame] | 226 | } |
Nick Kralevich | 8bafa74 | 2013-06-20 12:17:44 -0700 | [diff] [blame] | 227 | |
| 228 | TEST(Fortify2_DeathTest, strlcpy_fortified) { |
| 229 | ::testing::FLAGS_gtest_death_test_style = "threadsafe"; |
| 230 | char bufa[15]; |
| 231 | char bufb[10]; |
| 232 | strcpy(bufa, "01234567890123"); |
| 233 | size_t n = strlen(bufa); |
| 234 | ASSERT_EXIT(strlcpy(bufb, bufa, n), testing::KilledBySignal(SIGABRT), ""); |
| 235 | } |
| 236 | |
Nick Kralevich | 1aae9bd | 2013-04-29 14:07:06 -0700 | [diff] [blame] | 237 | #endif |
Nick Kralevich | 78d6d98 | 2013-04-29 16:29:37 -0700 | [diff] [blame] | 238 | |
| 239 | TEST(Fortify2_DeathTest, sprintf_fortified) { |
| 240 | ::testing::FLAGS_gtest_death_test_style = "threadsafe"; |
| 241 | char buf[10]; |
| 242 | char source_buf[15]; |
| 243 | memcpy(source_buf, "12345678901234", 15); |
Nick Kralevich | fd0325b | 2013-06-11 15:45:23 -0700 | [diff] [blame] | 244 | ASSERT_EXIT(sprintf(buf, "%s", source_buf), testing::KilledBySignal(SIGABRT), ""); |
Nick Kralevich | 78d6d98 | 2013-04-29 16:29:37 -0700 | [diff] [blame] | 245 | } |
Nick Kralevich | 8cc145e | 2013-05-30 13:21:14 -0700 | [diff] [blame] | 246 | |
Nick Kralevich | c6eb985 | 2013-06-24 11:44:00 -0700 | [diff] [blame] | 247 | TEST(Fortify2_DeathTest, sprintf2_fortified) { |
| 248 | ::testing::FLAGS_gtest_death_test_style = "threadsafe"; |
| 249 | char buf[5]; |
| 250 | ASSERT_EXIT(sprintf(buf, "aaaaa"), testing::KilledBySignal(SIGABRT), ""); |
| 251 | } |
| 252 | |
Nick Kralevich | 8cc145e | 2013-05-30 13:21:14 -0700 | [diff] [blame] | 253 | TEST(Fortify2_DeathTest, strncat_fortified) { |
| 254 | ::testing::FLAGS_gtest_death_test_style = "threadsafe"; |
| 255 | char buf[10]; |
| 256 | size_t n = atoi("10"); // avoid compiler optimizations |
| 257 | strncpy(buf, "012345678", n); |
Nick Kralevich | fd0325b | 2013-06-11 15:45:23 -0700 | [diff] [blame] | 258 | ASSERT_EXIT(strncat(buf, "9", n), testing::KilledBySignal(SIGABRT), ""); |
Nick Kralevich | 8cc145e | 2013-05-30 13:21:14 -0700 | [diff] [blame] | 259 | } |
| 260 | |
| 261 | TEST(Fortify2_DeathTest, strncat2_fortified) { |
| 262 | ::testing::FLAGS_gtest_death_test_style = "threadsafe"; |
| 263 | char buf[10]; |
| 264 | buf[0] = '\0'; |
| 265 | size_t n = atoi("10"); // avoid compiler optimizations |
Nick Kralevich | fd0325b | 2013-06-11 15:45:23 -0700 | [diff] [blame] | 266 | ASSERT_EXIT(strncat(buf, "0123456789", n), testing::KilledBySignal(SIGABRT), ""); |
Nick Kralevich | 8cc145e | 2013-05-30 13:21:14 -0700 | [diff] [blame] | 267 | } |
Nick Kralevich | cf87019 | 2013-05-30 16:48:53 -0700 | [diff] [blame] | 268 | |
| 269 | TEST(Fortify2_DeathTest, strcat_fortified) { |
| 270 | ::testing::FLAGS_gtest_death_test_style = "threadsafe"; |
| 271 | char src[11]; |
| 272 | strcpy(src, "0123456789"); |
| 273 | char buf[10]; |
| 274 | buf[0] = '\0'; |
Nick Kralevich | fd0325b | 2013-06-11 15:45:23 -0700 | [diff] [blame] | 275 | ASSERT_EXIT(strcat(buf, src), testing::KilledBySignal(SIGABRT), ""); |
Nick Kralevich | cf87019 | 2013-05-30 16:48:53 -0700 | [diff] [blame] | 276 | } |
Nick Kralevich | 16d1af1 | 2013-06-17 14:49:19 -0700 | [diff] [blame] | 277 | |
| 278 | TEST(Fortify2_DeathTest, memmove_fortified) { |
| 279 | ::testing::FLAGS_gtest_death_test_style = "threadsafe"; |
| 280 | char buf[20]; |
| 281 | strcpy(buf, "0123456789"); |
| 282 | size_t n = atoi("10"); |
| 283 | ASSERT_EXIT(memmove(buf + 11, buf, n), testing::KilledBySignal(SIGABRT), ""); |
| 284 | } |
| 285 | |
| 286 | TEST(Fortify2_DeathTest, memcpy_fortified) { |
| 287 | ::testing::FLAGS_gtest_death_test_style = "threadsafe"; |
| 288 | char bufa[10]; |
| 289 | char bufb[10]; |
| 290 | strcpy(bufa, "012345678"); |
| 291 | size_t n = atoi("11"); |
| 292 | ASSERT_EXIT(memcpy(bufb, bufa, n), testing::KilledBySignal(SIGABRT), ""); |
| 293 | } |
| 294 | |
| 295 | TEST(Fortify2_DeathTest, strncpy_fortified) { |
| 296 | ::testing::FLAGS_gtest_death_test_style = "threadsafe"; |
| 297 | char bufa[15]; |
| 298 | char bufb[10]; |
| 299 | strcpy(bufa, "01234567890123"); |
| 300 | size_t n = strlen(bufa); |
| 301 | ASSERT_EXIT(strncpy(bufb, bufa, n), testing::KilledBySignal(SIGABRT), ""); |
| 302 | } |
Nick Kralevich | 621b19d | 2013-06-25 10:02:35 -0700 | [diff] [blame] | 303 | |
| 304 | TEST(Fortify2_DeathTest, snprintf_fortified) { |
| 305 | ::testing::FLAGS_gtest_death_test_style = "threadsafe"; |
| 306 | char bufa[15]; |
| 307 | char bufb[10]; |
| 308 | strcpy(bufa, "0123456789"); |
| 309 | size_t n = strlen(bufa) + 1; |
| 310 | ASSERT_EXIT(snprintf(bufb, n, "%s", bufa), testing::KilledBySignal(SIGABRT), ""); |
| 311 | } |