• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 #include <errno.h>
16 #include <signal.h>
17 #include <stdlib.h>
18 #include <string.h>
19 #include <sys/stat.h>
20 #include <sys/wait.h>
21 #include "fortify_test.h"
22 #include "test.h"
23 
24 /**
25  * @tc.name     : umask_0010
26  * @tc.desc     : test umask normal condition
27  * @tc.level    : Level 0
28  */
umask_0010(void)29 static void umask_0010(void)
30 {
31     mode_t mask = atoi("077");
32     umask(mask);
33 
34     return;
35 }
36 
37 /**
38  * @tc.name     : umask_0020
39  * @tc.desc     : test umask suppress compiler optimizations
40  * @tc.level    : Level 2
41  */
umask_0020(void)42 static void umask_0020(void)
43 {
44     struct sigaction sigabrt = {
45         .sa_handler = SignalHandler,
46     };
47     sigaction(SIGABRT, &sigabrt, NULL);
48 
49     mode_t mask = atoi("1023");  // 01777 in octal
50     int status;
51     int pid = fork();
52     switch (pid) {
53         case -1:
54             t_error("fork failed: %s\n", strerror(errno));
55             break;
56         case 0:
57             umask(mask);
58             exit(0);
59         default:
60             waitpid(pid, &status, WUNTRACED);
61             TEST(WIFEXITED(status) == 0);
62             TEST(WIFSTOPPED(status) == 1);
63             TEST(WSTOPSIG(status) == SIGSTOP);
64             kill(pid, SIGCONT);
65             break;
66     }
67 
68     return;
69 }
70 
main(int argc,char * argv[])71 int main(int argc, char *argv[]) {
72     umask_0010();
73     umask_0020();
74 
75     return t_status;
76 }