am 72f59c84: Merge "Add strncpy FORTIFY_SOURCE tests."
				
					
				
			* commit '72f59c84fd73a0a701ce6448d103e9021c1cb060': Add strncpy FORTIFY_SOURCE tests.
This commit is contained in:
		@@ -60,3 +60,19 @@ TEST(Fortify1_DeathTest, sprintf_fortified) {
 | 
				
			|||||||
  memcpy(source_buf, "12345678901234", 15);
 | 
					  memcpy(source_buf, "12345678901234", 15);
 | 
				
			||||||
  ASSERT_EXIT(sprintf(buf, "%s", source_buf), testing::KilledBySignal(SIGSEGV), "");
 | 
					  ASSERT_EXIT(sprintf(buf, "%s", source_buf), testing::KilledBySignal(SIGSEGV), "");
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					TEST(Fortify1_DeathTest, strncat_fortified) {
 | 
				
			||||||
 | 
					  ::testing::FLAGS_gtest_death_test_style = "threadsafe";
 | 
				
			||||||
 | 
					  char buf[10];
 | 
				
			||||||
 | 
					  size_t n = atoi("10"); // avoid compiler optimizations
 | 
				
			||||||
 | 
					  strncpy(buf, "012345678", n);
 | 
				
			||||||
 | 
					  ASSERT_EXIT(strncat(buf, "9", n), testing::KilledBySignal(SIGSEGV), "");
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					TEST(Fortify1_DeathTest, strncat2_fortified) {
 | 
				
			||||||
 | 
					  ::testing::FLAGS_gtest_death_test_style = "threadsafe";
 | 
				
			||||||
 | 
					  char buf[10];
 | 
				
			||||||
 | 
					  buf[0] = '\0';
 | 
				
			||||||
 | 
					  size_t n = atoi("10"); // avoid compiler optimizations
 | 
				
			||||||
 | 
					  ASSERT_EXIT(strncat(buf, "0123456789", n), testing::KilledBySignal(SIGSEGV), "");
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -64,6 +64,22 @@ TEST(Fortify2_DeathTest, strrchr_fortified2) {
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					TEST(Fortify2_DeathTest, strncat_fortified2) {
 | 
				
			||||||
 | 
					  ::testing::FLAGS_gtest_death_test_style = "threadsafe";
 | 
				
			||||||
 | 
					  foo myfoo;
 | 
				
			||||||
 | 
					  size_t n = atoi("10"); // avoid compiler optimizations
 | 
				
			||||||
 | 
					  strncpy(myfoo.a, "012345678", n);
 | 
				
			||||||
 | 
					  ASSERT_EXIT(strncat(myfoo.a, "9", n), testing::KilledBySignal(SIGSEGV), "");
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					TEST(Fortify2_DeathTest, strncat2_fortified2) {
 | 
				
			||||||
 | 
					  ::testing::FLAGS_gtest_death_test_style = "threadsafe";
 | 
				
			||||||
 | 
					  foo myfoo;
 | 
				
			||||||
 | 
					  myfoo.a[0] = '\0';
 | 
				
			||||||
 | 
					  size_t n = atoi("10"); // avoid compiler optimizations
 | 
				
			||||||
 | 
					  ASSERT_EXIT(strncat(myfoo.a, "0123456789", n), testing::KilledBySignal(SIGSEGV), "");
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/***********************************************************/
 | 
					/***********************************************************/
 | 
				
			||||||
/* TESTS BELOW HERE DUPLICATE TESTS FROM fortify1_test.cpp */
 | 
					/* TESTS BELOW HERE DUPLICATE TESTS FROM fortify1_test.cpp */
 | 
				
			||||||
/***********************************************************/
 | 
					/***********************************************************/
 | 
				
			||||||
@@ -106,3 +122,19 @@ TEST(Fortify2_DeathTest, sprintf_fortified) {
 | 
				
			|||||||
  memcpy(source_buf, "12345678901234", 15);
 | 
					  memcpy(source_buf, "12345678901234", 15);
 | 
				
			||||||
  ASSERT_EXIT(sprintf(buf, "%s", source_buf), testing::KilledBySignal(SIGSEGV), "");
 | 
					  ASSERT_EXIT(sprintf(buf, "%s", source_buf), testing::KilledBySignal(SIGSEGV), "");
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					TEST(Fortify2_DeathTest, strncat_fortified) {
 | 
				
			||||||
 | 
					  ::testing::FLAGS_gtest_death_test_style = "threadsafe";
 | 
				
			||||||
 | 
					  char buf[10];
 | 
				
			||||||
 | 
					  size_t n = atoi("10"); // avoid compiler optimizations
 | 
				
			||||||
 | 
					  strncpy(buf, "012345678", n);
 | 
				
			||||||
 | 
					  ASSERT_EXIT(strncat(buf, "9", n), testing::KilledBySignal(SIGSEGV), "");
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					TEST(Fortify2_DeathTest, strncat2_fortified) {
 | 
				
			||||||
 | 
					  ::testing::FLAGS_gtest_death_test_style = "threadsafe";
 | 
				
			||||||
 | 
					  char buf[10];
 | 
				
			||||||
 | 
					  buf[0] = '\0';
 | 
				
			||||||
 | 
					  size_t n = atoi("10"); // avoid compiler optimizations
 | 
				
			||||||
 | 
					  ASSERT_EXIT(strncat(buf, "0123456789", n), testing::KilledBySignal(SIGSEGV), "");
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user