1 #include <sys/socket.h>
2 #include <fortify/socket.h>
3 #include <gtest/gtest.h>
4 #include <sys/types.h>
5 #include <sys/wait.h>
6
7 constexpr int BUF_SIZE = 10;
8
9 using namespace testing::ext;
10
11 constexpr size_t DATA_LEN = 11;
12
13 class FortifySendtochkTest : public testing::Test {
SetUp()14 void SetUp() override {}
TearDown()15 void TearDown() override {}
16 };
17
SignalHandler(int signum)18 static void SignalHandler(int signum)
19 {
20 kill(getpid(), SIGSTOP);
21 }
22
23 /**
24 * @tc.name: __sendto_chk_001
25 * @tc.desc: Verify if the __sendto_chk is functioning properly.
26 * @tc.type: FUNC
27 * */
28 HWTEST_F(FortifySendtochkTest, __sendto_chk_001, TestSize.Level1)
29 {
30 struct sigaction signalAbort = {
31 .sa_handler = SignalHandler,
32 };
33 sigaction(SIGABRT, &signalAbort, nullptr);
34 char buf[BUF_SIZE];
35 int status;
36 int pid = fork();
37 if (pid == 0) {
38 __sendto_chk(0, buf, DATA_LEN, DATA_LEN, 0, nullptr, 0);
39 exit(0);
40 } else if (pid > 0) {
41 waitpid(pid, &status, WUNTRACED);
42 EXPECT_TRUE(WIFEXITED(status));
43 EXPECT_FALSE(WIFSTOPPED(status));
44 kill(pid, SIGCONT);
45 } else {
46 FAIL();
47 }
48 }
49