OpenCoverage

mktemp.c

Absolute File Name:/home/opencoverage/opencoverage/guest-scripts/openssh/src/openbsd-compat/mktemp.c
Switch to Source codePreprocessed file
LineSourceCount
1-
2-
3-
4-
5-
6-
7static int-
8mktemp_internal(char *path, int slen, int mode)-
9{-
10 char *start, *cp, *ep;-
11 const char *tempchars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";-
12 unsigned int r, tries;-
13 struct stat sb;-
14 size_t len;-
15 int fd;-
16-
17 len = strlen(path);-
18 if (len == 0
len == 0Description
TRUEnever evaluated
FALSEnever evaluated
|| slen < 0
slen < 0Description
TRUEnever evaluated
FALSEnever evaluated
|| (
(size_t)slen >= lenDescription
TRUEnever evaluated
FALSEnever evaluated
size_t)slen >= len
(size_t)slen >= lenDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
19 -
20 (*__errno_location ()) -
21 = -
22 22-
23 ;-
24 return
never executed: return(-1);
(-1);
never executed: return(-1);
0
25 }-
26 ep = path + len - slen;-
27-
28 tries = 1;-
29 for (start = ep; start > path
start > pathDescription
TRUEnever evaluated
FALSEnever evaluated
&& start[-1] == 'X'
start[-1] == 'X'Description
TRUEnever evaluated
FALSEnever evaluated
; start--) {
0
30 if (tries < 0x7fffffff / (sizeof("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789") - 1)
tries < 0x7fff...3456789") - 1)Description
TRUEnever evaluated
FALSEnever evaluated
)
0
31 tries *= (sizeof("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789") - 1);
never executed: tries *= (sizeof("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789") - 1);
0
32 }
never executed: end of block
0
33 tries *= 2;-
34-
35 do {-
36 for (cp = start; cp != ep
cp != epDescription
TRUEnever evaluated
FALSEnever evaluated
; cp++) {
0
37 r = arc4random_uniform((sizeof("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789") - 1));-
38 *cp = tempchars[r];-
39 }
never executed: end of block
0
40-
41 switch (mode) {-
42 case
never executed: case 0:
0:
never executed: case 0:
0
43 if (lstat(path, &sb) != 0
lstat(path, &sb) != 0Description
TRUEnever evaluated
FALSEnever evaluated
)
0
44 return
never executed: return( (*__errno_location ()) == 2 ? 0 : -1);
(
never executed: return( (*__errno_location ()) == 2 ? 0 : -1);
0
45 (*
(*__errno_location ()) == 2Description
TRUEnever evaluated
FALSEnever evaluated
__errno_location ())
(*__errno_location ()) == 2Description
TRUEnever evaluated
FALSEnever evaluated
never executed: return( (*__errno_location ()) == 2 ? 0 : -1);
0
46 ==
(*__errno_location ()) == 2Description
TRUEnever evaluated
FALSEnever evaluated
never executed: return( (*__errno_location ()) == 2 ? 0 : -1);
0
47 2
(*__errno_location ()) == 2Description
TRUEnever evaluated
FALSEnever evaluated
never executed: return( (*__errno_location ()) == 2 ? 0 : -1);
0
48 ? 0 : -1);
never executed: return( (*__errno_location ()) == 2 ? 0 : -1);
0
49 break;
never executed: break;
0
50 case
never executed: case 1:
1:
never executed: case 1:
0
51 fd = open(path, -
52 0100-
53 |-
54 0200-
55 |-
56 02-
57 , -
58 0400-
59 |-
60 0200-
61 );-
62 if (fd != -1
fd != -1Description
TRUEnever evaluated
FALSEnever evaluated
||
0
63 (*
(*__errno_location ()) != 17Description
TRUEnever evaluated
FALSEnever evaluated
__errno_location ())
(*__errno_location ()) != 17Description
TRUEnever evaluated
FALSEnever evaluated
0
64 !=
(*__errno_location ()) != 17Description
TRUEnever evaluated
FALSEnever evaluated
0
65 17
(*__errno_location ()) != 17Description
TRUEnever evaluated
FALSEnever evaluated
0
66 )-
67 return
never executed: return(fd);
(fd);
never executed: return(fd);
0
68 break;
never executed: break;
0
69 case
never executed: case 2:
2:
never executed: case 2:
0
70 if (mkdir(path,
mkdir(path, 04... | 0100 ) == 0Description
TRUEnever evaluated
FALSEnever evaluated
0
71 0400
mkdir(path, 04... | 0100 ) == 0Description
TRUEnever evaluated
FALSEnever evaluated
0
72 |
mkdir(path, 04... | 0100 ) == 0Description
TRUEnever evaluated
FALSEnever evaluated
0
73 0200
mkdir(path, 04... | 0100 ) == 0Description
TRUEnever evaluated
FALSEnever evaluated
0
74 |
mkdir(path, 04... | 0100 ) == 0Description
TRUEnever evaluated
FALSEnever evaluated
0
75 0100
mkdir(path, 04... | 0100 ) == 0Description
TRUEnever evaluated
FALSEnever evaluated
0
76 ) == 0
mkdir(path, 04... | 0100 ) == 0Description
TRUEnever evaluated
FALSEnever evaluated
)
0
77 return
never executed: return(0);
(0);
never executed: return(0);
0
78 if (-
79 (*
(*__errno_location ()) != 17Description
TRUEnever evaluated
FALSEnever evaluated
__errno_location ())
(*__errno_location ()) != 17Description
TRUEnever evaluated
FALSEnever evaluated
0
80 !=
(*__errno_location ()) != 17Description
TRUEnever evaluated
FALSEnever evaluated
0
81 17
(*__errno_location ()) != 17Description
TRUEnever evaluated
FALSEnever evaluated
0
82 )-
83 return
never executed: return(-1);
(-1);
never executed: return(-1);
0
84 break;
never executed: break;
0
85 }-
86 }
never executed: end of block
while (--
--triesDescription
TRUEnever evaluated
FALSEnever evaluated
tries
--triesDescription
TRUEnever evaluated
FALSEnever evaluated
);
0
87-
88 -
89(*__errno_location ()) -
90 = -
91 17-
92 ;-
93 return
never executed: return(-1);
(-1);
never executed: return(-1);
0
94}-
95int-
96mkstemp(char *path)-
97{-
98 return
never executed: return(mktemp_internal(path, 0, 1));
(mktemp_internal(path, 0, 1));
never executed: return(mktemp_internal(path, 0, 1));
0
99}-
100-
101int-
102mkstemps(char *path, int slen)-
103{-
104 return
never executed: return(mktemp_internal(path, slen, 1));
(mktemp_internal(path, slen, 1));
never executed: return(mktemp_internal(path, slen, 1));
0
105}-
106-
107char *-
108mkdtemp(char *path)-
109{-
110 int error;-
111-
112 error = mktemp_internal(path, 0, 2);-
113 return
never executed: return(error ? ((void *)0) : path);
(error
errorDescription
TRUEnever evaluated
FALSEnever evaluated
?
never executed: return(error ? ((void *)0) : path);
0
114 ((void *)0)
never executed: return(error ? ((void *)0) : path);
0
115 : path);
never executed: return(error ? ((void *)0) : path);
0
116}-
Switch to Source codePreprocessed file

Generated by Squish Coco 4.2.2