• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #include <gtest/gtest.h>
2 #include <string.h>
3 
4 constexpr int BUF_SIZE = 10;
5 
6 using namespace testing::ext;
7 
8 class FortifyStpcpychkTest : public testing::Test {
SetUp()9     void SetUp() override {}
TearDown()10     void TearDown() override {}
11 };
12 
13 extern "C" char* __stpcpy_chk(char* dest, const char* src, size_t dst_len);
14 
15 /**
16  * @tc.name: __strcpy_chk_001
17  * @tc.desc: Verify whether the __stpcpy_chk can correctly process the result and avoid buffer overflow if the specified
18  *           buffer size is an invalid value (-1) when connecting strings.
19  * @tc.type: FUNC
20  * */
21 HWTEST_F(FortifyStpcpychkTest, __stpcpy_chk_001, TestSize.Level1)
22 {
23     char buf[BUF_SIZE];
24     memset(buf, 'A', sizeof(buf));
25 
26     const char* src = "Hello";
27     char* dest = buf;
28     __stpcpy_chk(dest, src, static_cast<size_t>(-1));
29     EXPECT_STREQ(src, dest);
30 }