OpenCoverage

userspec.c

Absolute File Name:/home/opencoverage/opencoverage/guest-scripts/coreutils/src/gnulib/lib/userspec.c
Switch to Source codePreprocessed file
LineSourceCount
1-
2-
3-
4-
5-
6-
7-
8-
9-
10-
11-
12static char const *-
13parse_with_separator (char const *spec, char const *separator,-
14 uid_t *uid, gid_t *gid,-
15 char **username, char **groupname)-
16{-
17 static const char *E_invalid_user = "invalid user";-
18 static const char *E_invalid_group = "invalid group";-
19 static const char *E_bad_spec = "invalid spec";-
20-
21 const char *error_msg;-
22 struct passwd *pwd;-
23 struct group *grp;-
24 char *u;-
25 char const *g;-
26 char *gname = -
27 ((void *)0)-
28 ;-
29 uid_t unum = *uid;-
30 gid_t gnum = gid
gidDescription
TRUEevaluated 44 times by 1 test
Evaluated by:
  • chown
FALSEevaluated 113 times by 1 test
Evaluated by:
  • id
? *gid : -1;
44-113
31-
32 error_msg = -
33 ((void *)0)-
34 ;-
35 if (username
usernameDescription
TRUEevaluated 38 times by 1 test
Evaluated by:
  • chown
FALSEevaluated 119 times by 2 tests
Evaluated by:
  • chown
  • id
)
38-119
36 *
executed 38 times by 1 test: *username = ((void *)0) ;
Executed by:
  • chown
username =
executed 38 times by 1 test: *username = ((void *)0) ;
Executed by:
  • chown
38
37 ((void *)0)
executed 38 times by 1 test: *username = ((void *)0) ;
Executed by:
  • chown
38
38 ;
executed 38 times by 1 test: *username = ((void *)0) ;
Executed by:
  • chown
38
39 if (groupname
groupnameDescription
TRUEevaluated 38 times by 1 test
Evaluated by:
  • chown
FALSEevaluated 119 times by 2 tests
Evaluated by:
  • chown
  • id
)
38-119
40 *
executed 38 times by 1 test: *groupname = ((void *)0) ;
Executed by:
  • chown
groupname =
executed 38 times by 1 test: *groupname = ((void *)0) ;
Executed by:
  • chown
38
41 ((void *)0)
executed 38 times by 1 test: *groupname = ((void *)0) ;
Executed by:
  • chown
38
42 ;
executed 38 times by 1 test: *groupname = ((void *)0) ;
Executed by:
  • chown
38
43-
44-
45-
46-
47-
48 u = -
49 ((void *)0)-
50 ;-
51 if (separator ==
separator == ((void *)0)Description
TRUEevaluated 128 times by 2 tests
Evaluated by:
  • chown
  • id
FALSEevaluated 29 times by 1 test
Evaluated by:
  • chown
29-128
52 ((void *)0)
separator == ((void *)0)Description
TRUEevaluated 128 times by 2 tests
Evaluated by:
  • chown
  • id
FALSEevaluated 29 times by 1 test
Evaluated by:
  • chown
29-128
53 )-
54 {-
55 if (*
*specDescription
TRUEevaluated 127 times by 2 tests
Evaluated by:
  • chown
  • id
FALSEevaluated 1 time by 1 test
Evaluated by:
  • chown
spec
*specDescription
TRUEevaluated 127 times by 2 tests
Evaluated by:
  • chown
  • id
FALSEevaluated 1 time by 1 test
Evaluated by:
  • chown
)
1-127
56 u = xstrdup (spec);
executed 127 times by 2 tests: u = xstrdup (spec);
Executed by:
  • chown
  • id
127
57 }
executed 128 times by 2 tests: end of block
Executed by:
  • chown
  • id
128
58 else-
59 {-
60 size_t ulen = separator - spec;-
61 if (ulen != 0
ulen != 0Description
TRUEevaluated 13 times by 1 test
Evaluated by:
  • chown
FALSEevaluated 16 times by 1 test
Evaluated by:
  • chown
)
13-16
62 {-
63 u = xmemdup (spec, ulen + 1);-
64 u[ulen] = '\0';-
65 }
executed 13 times by 1 test: end of block
Executed by:
  • chown
13
66 }
executed 29 times by 1 test: end of block
Executed by:
  • chown
29
67-
68 g = (separator ==
separator == ((void *)0)Description
TRUEevaluated 128 times by 2 tests
Evaluated by:
  • chown
  • id
FALSEevaluated 29 times by 1 test
Evaluated by:
  • chown
29-128
69 ((void *)0)
separator == ((void *)0)Description
TRUEevaluated 128 times by 2 tests
Evaluated by:
  • chown
  • id
FALSEevaluated 29 times by 1 test
Evaluated by:
  • chown
29-128
70 || *(
*(separator + 1) == '\0'Description
TRUEevaluated 6 times by 1 test
Evaluated by:
  • chown
FALSEevaluated 23 times by 1 test
Evaluated by:
  • chown
separator + 1) == '\0'
*(separator + 1) == '\0'Description
TRUEevaluated 6 times by 1 test
Evaluated by:
  • chown
FALSEevaluated 23 times by 1 test
Evaluated by:
  • chown
6-23
71 ? -
72 ((void *)0)-
73 -
74 : separator + 1);-
75 if (u !=
u != ((void *)0)Description
TRUEevaluated 140 times by 2 tests
Evaluated by:
  • chown
  • id
FALSEevaluated 17 times by 1 test
Evaluated by:
  • chown
17-140
76 ((void *)0)
u != ((void *)0)Description
TRUEevaluated 140 times by 2 tests
Evaluated by:
  • chown
  • id
FALSEevaluated 17 times by 1 test
Evaluated by:
  • chown
17-140
77 )-
78 {-
79-
80 pwd = (*
*u == '+'Description
TRUEevaluated 3 times by 1 test
Evaluated by:
  • id
FALSEevaluated 137 times by 2 tests
Evaluated by:
  • chown
  • id
u == '+'
*u == '+'Description
TRUEevaluated 3 times by 1 test
Evaluated by:
  • id
FALSEevaluated 137 times by 2 tests
Evaluated by:
  • chown
  • id
?
3-137
81 ((void *)0) -
82 : getpwnam (u));-
83 if (pwd ==
pwd == ((void *)0)Description
TRUEevaluated 28 times by 2 tests
Evaluated by:
  • chown
  • id
FALSEevaluated 112 times by 2 tests
Evaluated by:
  • chown
  • id
28-112
84 ((void *)0)
pwd == ((void *)0)Description
TRUEevaluated 28 times by 2 tests
Evaluated by:
  • chown
  • id
FALSEevaluated 112 times by 2 tests
Evaluated by:
  • chown
  • id
28-112
85 )-
86 {-
87 -
88 _Bool -
89 use_login_group = (separator !=
separator != ((void *)0)Description
TRUEevaluated 7 times by 1 test
Evaluated by:
  • chown
FALSEevaluated 21 times by 2 tests
Evaluated by:
  • chown
  • id
7-21
90 ((void *)0)
separator != ((void *)0)Description
TRUEevaluated 7 times by 1 test
Evaluated by:
  • chown
FALSEevaluated 21 times by 2 tests
Evaluated by:
  • chown
  • id
7-21
91 && g ==
g == ((void *)0)Description
TRUEevaluated 2 times by 1 test
Evaluated by:
  • chown
FALSEevaluated 5 times by 1 test
Evaluated by:
  • chown
2-5
92 ((void *)0)
g == ((void *)0)Description
TRUEevaluated 2 times by 1 test
Evaluated by:
  • chown
FALSEevaluated 5 times by 1 test
Evaluated by:
  • chown
2-5
93 );-
94 if (use_login_group
use_login_groupDescription
TRUEevaluated 2 times by 1 test
Evaluated by:
  • chown
FALSEevaluated 26 times by 2 tests
Evaluated by:
  • chown
  • id
)
2-26
95 {-
96-
97-
98 error_msg = E_bad_spec;-
99 }
executed 2 times by 1 test: end of block
Executed by:
  • chown
2
100 else-
101 {-
102 unsigned long int tmp;-
103 if (xstrtoul (u,
xstrtoul (u, (... == LONGINT_OKDescription
TRUEevaluated 14 times by 2 tests
Evaluated by:
  • chown
  • id
FALSEevaluated 12 times by 2 tests
Evaluated by:
  • chown
  • id
12-14
104 ((void *)0)
xstrtoul (u, (... == LONGINT_OKDescription
TRUEevaluated 14 times by 2 tests
Evaluated by:
  • chown
  • id
FALSEevaluated 12 times by 2 tests
Evaluated by:
  • chown
  • id
12-14
105 , 10, &tmp, "") == LONGINT_OK
xstrtoul (u, (... == LONGINT_OKDescription
TRUEevaluated 14 times by 2 tests
Evaluated by:
  • chown
  • id
FALSEevaluated 12 times by 2 tests
Evaluated by:
  • chown
  • id
12-14
106 && tmp <= ((uid_t) (! (! ((uid_t) 0 < (uid_t) -1)) ? (uid_t) -1 : ((((uid_t) 1 << ((sizeof (uid_t) * 8) - 2)) - 1) * 2 + 1)))
tmp <= ((uid_t... 1) * 2 + 1)))Description
TRUEevaluated 14 times by 2 tests
Evaluated by:
  • chown
  • id
FALSEnever evaluated
&& (
(uid_t) tmp != (uid_t) -1Description
TRUEevaluated 14 times by 2 tests
Evaluated by:
  • chown
  • id
FALSEnever evaluated
uid_t) tmp != (uid_t) -1
(uid_t) tmp != (uid_t) -1Description
TRUEevaluated 14 times by 2 tests
Evaluated by:
  • chown
  • id
FALSEnever evaluated
)
0-14
107 unum = tmp;
executed 14 times by 2 tests: unum = tmp;
Executed by:
  • chown
  • id
14
108 else-
109 error_msg = E_invalid_user;
executed 12 times by 2 tests: error_msg = E_invalid_user;
Executed by:
  • chown
  • id
12
110 }-
111 }-
112 else-
113 {-
114 unum = pwd->pw_uid;-
115 if (g ==
g == ((void *)0)Description
TRUEevaluated 108 times by 2 tests
Evaluated by:
  • chown
  • id
FALSEevaluated 4 times by 1 test
Evaluated by:
  • chown
4-108
116 ((void *)0)
g == ((void *)0)Description
TRUEevaluated 108 times by 2 tests
Evaluated by:
  • chown
  • id
FALSEevaluated 4 times by 1 test
Evaluated by:
  • chown
4-108
117 && separator !=
separator != ((void *)0)Description
TRUEevaluated 2 times by 1 test
Evaluated by:
  • chown
FALSEevaluated 106 times by 2 tests
Evaluated by:
  • chown
  • id
2-106
118 ((void *)0)
separator != ((void *)0)Description
TRUEevaluated 2 times by 1 test
Evaluated by:
  • chown
FALSEevaluated 106 times by 2 tests
Evaluated by:
  • chown
  • id
2-106
119 )-
120 {-
121-
122-
123 char buf[((((((sizeof (uintmax_t) * 8) - (! ((__typeof__ (uintmax_t)) 0 < (__typeof__ (uintmax_t)) -1))) * 146 + 484) / 485) + (! ((__typeof__ (uintmax_t)) 0 < (__typeof__ (uintmax_t)) -1))) + 1)];-
124 gnum = pwd->pw_gid;-
125 grp = getgrgid (gnum);-
126 gname = xstrdup (grp ? grp->gr_name : umaxtostr (gnum, buf));-
127 endgrent ();-
128 }
executed 2 times by 1 test: end of block
Executed by:
  • chown
2
129 }
executed 112 times by 2 tests: end of block
Executed by:
  • chown
  • id
112
130 endpwent ();-
131 }
executed 140 times by 2 tests: end of block
Executed by:
  • chown
  • id
140
132-
133 if (g !=
g != ((void *)0)Description
TRUEevaluated 23 times by 1 test
Evaluated by:
  • chown
FALSEevaluated 134 times by 2 tests
Evaluated by:
  • chown
  • id
23-134
134 ((void *)0)
g != ((void *)0)Description
TRUEevaluated 23 times by 1 test
Evaluated by:
  • chown
FALSEevaluated 134 times by 2 tests
Evaluated by:
  • chown
  • id
23-134
135 && error_msg ==
error_msg == ((void *)0)Description
TRUEevaluated 23 times by 1 test
Evaluated by:
  • chown
FALSEnever evaluated
0-23
136 ((void *)0)
error_msg == ((void *)0)Description
TRUEevaluated 23 times by 1 test
Evaluated by:
  • chown
FALSEnever evaluated
0-23
137 )-
138 {-
139-
140-
141 grp = (*
*g == '+'Description
TRUEnever evaluated
FALSEevaluated 23 times by 1 test
Evaluated by:
  • chown
g == '+'
*g == '+'Description
TRUEnever evaluated
FALSEevaluated 23 times by 1 test
Evaluated by:
  • chown
?
0-23
142 ((void *)0) -
143 : getgrnam (g));-
144 if (grp ==
grp == ((void *)0)Description
TRUEevaluated 17 times by 1 test
Evaluated by:
  • chown
FALSEevaluated 6 times by 1 test
Evaluated by:
  • chown
6-17
145 ((void *)0)
grp == ((void *)0)Description
TRUEevaluated 17 times by 1 test
Evaluated by:
  • chown
FALSEevaluated 6 times by 1 test
Evaluated by:
  • chown
6-17
146 )-
147 {-
148 unsigned long int tmp;-
149 if (xstrtoul (g,
xstrtoul (g, (... == LONGINT_OKDescription
TRUEevaluated 17 times by 1 test
Evaluated by:
  • chown
FALSEnever evaluated
0-17
150 ((void *)0)
xstrtoul (g, (... == LONGINT_OKDescription
TRUEevaluated 17 times by 1 test
Evaluated by:
  • chown
FALSEnever evaluated
0-17
151 , 10, &tmp, "") == LONGINT_OK
xstrtoul (g, (... == LONGINT_OKDescription
TRUEevaluated 17 times by 1 test
Evaluated by:
  • chown
FALSEnever evaluated
0-17
152 && tmp <= ((gid_t) (! (! ((gid_t) 0 < (gid_t) -1)) ? (gid_t) -1 : ((((gid_t) 1 << ((sizeof (gid_t) * 8) - 2)) - 1) * 2 + 1)))
tmp <= ((gid_t... 1) * 2 + 1)))Description
TRUEevaluated 17 times by 1 test
Evaluated by:
  • chown
FALSEnever evaluated
&& (
(gid_t) tmp != (gid_t) -1Description
TRUEevaluated 17 times by 1 test
Evaluated by:
  • chown
FALSEnever evaluated
gid_t) tmp != (gid_t) -1
(gid_t) tmp != (gid_t) -1Description
TRUEevaluated 17 times by 1 test
Evaluated by:
  • chown
FALSEnever evaluated
)
0-17
153 gnum = tmp;
executed 17 times by 1 test: gnum = tmp;
Executed by:
  • chown
17
154 else-
155 error_msg = E_invalid_group;
never executed: error_msg = E_invalid_group;
0
156 }-
157 else-
158 gnum = grp->gr_gid;
executed 6 times by 1 test: gnum = grp->gr_gid;
Executed by:
  • chown
6
159 endgrent ();-
160 gname = xstrdup (g);-
161 }
executed 23 times by 1 test: end of block
Executed by:
  • chown
23
162-
163 if (error_msg ==
error_msg == ((void *)0)Description
TRUEevaluated 143 times by 2 tests
Evaluated by:
  • chown
  • id
FALSEevaluated 14 times by 2 tests
Evaluated by:
  • chown
  • id
14-143
164 ((void *)0)
error_msg == ((void *)0)Description
TRUEevaluated 143 times by 2 tests
Evaluated by:
  • chown
  • id
FALSEevaluated 14 times by 2 tests
Evaluated by:
  • chown
  • id
14-143
165 )-
166 {-
167 *uid = unum;-
168 if (gid
gidDescription
TRUEevaluated 32 times by 1 test
Evaluated by:
  • chown
FALSEevaluated 111 times by 1 test
Evaluated by:
  • id
)
32-111
169 *
executed 32 times by 1 test: *gid = gnum;
Executed by:
  • chown
gid = gnum;
executed 32 times by 1 test: *gid = gnum;
Executed by:
  • chown
32
170 if (username
usernameDescription
TRUEevaluated 27 times by 1 test
Evaluated by:
  • chown
FALSEevaluated 116 times by 2 tests
Evaluated by:
  • chown
  • id
)
27-116
171 {-
172 *username = u;-
173 u = -
174 ((void *)0)-
175 ;-
176 }
executed 27 times by 1 test: end of block
Executed by:
  • chown
27
177 if (groupname
groupnameDescription
TRUEevaluated 27 times by 1 test
Evaluated by:
  • chown
FALSEevaluated 116 times by 2 tests
Evaluated by:
  • chown
  • id
)
27-116
178 {-
179 *groupname = gname;-
180 gname = -
181 ((void *)0)-
182 ;-
183 }
executed 27 times by 1 test: end of block
Executed by:
  • chown
27
184 }
executed 143 times by 2 tests: end of block
Executed by:
  • chown
  • id
143
185-
186 free (u);-
187 free (gname);-
188 return
executed 157 times by 2 tests: return error_msg ? dcgettext (((void *)0), error_msg , 5) : ((void *)0) ;
Executed by:
  • chown
  • id
error_msg ?
executed 157 times by 2 tests: return error_msg ? dcgettext (((void *)0), error_msg , 5) : ((void *)0) ;
Executed by:
  • chown
  • id
157
189 dcgettext (((void *)0),
executed 157 times by 2 tests: return error_msg ? dcgettext (((void *)0), error_msg , 5) : ((void *)0) ;
Executed by:
  • chown
  • id
157
190 error_msg
executed 157 times by 2 tests: return error_msg ? dcgettext (((void *)0), error_msg , 5) : ((void *)0) ;
Executed by:
  • chown
  • id
157
191 , 5)
executed 157 times by 2 tests: return error_msg ? dcgettext (((void *)0), error_msg , 5) : ((void *)0) ;
Executed by:
  • chown
  • id
157
192 :
executed 157 times by 2 tests: return error_msg ? dcgettext (((void *)0), error_msg , 5) : ((void *)0) ;
Executed by:
  • chown
  • id
157
193 ((void *)0)
executed 157 times by 2 tests: return error_msg ? dcgettext (((void *)0), error_msg , 5) : ((void *)0) ;
Executed by:
  • chown
  • id
157
194 ;
executed 157 times by 2 tests: return error_msg ? dcgettext (((void *)0), error_msg , 5) : ((void *)0) ;
Executed by:
  • chown
  • id
157
195}-
196char const *-
197parse_user_spec (char const *spec, uid_t *uid, gid_t *gid,-
198 char **username, char **groupname)-
199{-
200 char const *colon = gid
gidDescription
TRUEevaluated 35 times by 1 test
Evaluated by:
  • chown
FALSEevaluated 113 times by 1 test
Evaluated by:
  • id
?
35-113
201 (__extension__ (__builtin_constant_p (
__builtin_constant_p ( ':' )Description
TRUEevaluated 35 times by 1 test
Evaluated by:
  • chown
FALSEnever evaluated
0-35
202 ':'
__builtin_constant_p ( ':' )Description
TRUEevaluated 35 times by 1 test
Evaluated by:
  • chown
FALSEnever evaluated
0-35
203 )
__builtin_constant_p ( ':' )Description
TRUEevaluated 35 times by 1 test
Evaluated by:
  • chown
FALSEnever evaluated
&& !__builtin_constant_p (
!__builtin_constant_p ( spec )Description
TRUEevaluated 35 times by 1 test
Evaluated by:
  • chown
FALSEnever evaluated
0-35
204 spec
!__builtin_constant_p ( spec )Description
TRUEevaluated 35 times by 1 test
Evaluated by:
  • chown
FALSEnever evaluated
0-35
205 )
!__builtin_constant_p ( spec )Description
TRUEevaluated 35 times by 1 test
Evaluated by:
  • chown
FALSEnever evaluated
&& (
( ':' ) == '\0'Description
TRUEnever evaluated
FALSEevaluated 35 times by 1 test
Evaluated by:
  • chown
0-35
206 ':'
( ':' ) == '\0'Description
TRUEnever evaluated
FALSEevaluated 35 times by 1 test
Evaluated by:
  • chown
0-35
207 ) == '\0'
( ':' ) == '\0'Description
TRUEnever evaluated
FALSEevaluated 35 times by 1 test
Evaluated by:
  • chown
? (char *) __rawmemchr (
0-35
208 spec-
209 , -
210 ':'-
211 ) : __builtin_strchr (-
212 spec-
213 , -
214 ':'-
215 ))) -
216 : -
217 ((void *)0)-
218 ;-
219 char const *error_msg =-
220 parse_with_separator (spec, colon, uid, gid, username, groupname);-
221-
222 if (gid
gidDescription
TRUEevaluated 35 times by 1 test
Evaluated by:
  • chown
FALSEevaluated 113 times by 1 test
Evaluated by:
  • id
&& !colon
!colonDescription
TRUEevaluated 15 times by 1 test
Evaluated by:
  • chown
FALSEevaluated 20 times by 1 test
Evaluated by:
  • chown
&& error_msg
error_msgDescription
TRUEevaluated 10 times by 1 test
Evaluated by:
  • chown
FALSEevaluated 5 times by 1 test
Evaluated by:
  • chown
)
5-113
223 {-
224-
225-
226-
227-
228-
229-
230 char const *dot = -
231 (__extension__ (__builtin_constant_p (
__builtin_constant_p ( '.' )Description
TRUEevaluated 10 times by 1 test
Evaluated by:
  • chown
FALSEnever evaluated
0-10
232 '.'
__builtin_constant_p ( '.' )Description
TRUEevaluated 10 times by 1 test
Evaluated by:
  • chown
FALSEnever evaluated
0-10
233 )
__builtin_constant_p ( '.' )Description
TRUEevaluated 10 times by 1 test
Evaluated by:
  • chown
FALSEnever evaluated
&& !__builtin_constant_p (
!__builtin_constant_p ( spec )Description
TRUEevaluated 10 times by 1 test
Evaluated by:
  • chown
FALSEnever evaluated
0-10
234 spec
!__builtin_constant_p ( spec )Description
TRUEevaluated 10 times by 1 test
Evaluated by:
  • chown
FALSEnever evaluated
0-10
235 )
!__builtin_constant_p ( spec )Description
TRUEevaluated 10 times by 1 test
Evaluated by:
  • chown
FALSEnever evaluated
&& (
( '.' ) == '\0'Description
TRUEnever evaluated
FALSEevaluated 10 times by 1 test
Evaluated by:
  • chown
0-10
236 '.'
( '.' ) == '\0'Description
TRUEnever evaluated
FALSEevaluated 10 times by 1 test
Evaluated by:
  • chown
0-10
237 ) == '\0'
( '.' ) == '\0'Description
TRUEnever evaluated
FALSEevaluated 10 times by 1 test
Evaluated by:
  • chown
? (char *) __rawmemchr (
0-10
238 spec-
239 , -
240 '.'-
241 ) : __builtin_strchr (-
242 spec-
243 , -
244 '.'-
245 )))-
246 ;-
247 if (dot
dotDescription
TRUEevaluated 9 times by 1 test
Evaluated by:
  • chown
FALSEevaluated 1 time by 1 test
Evaluated by:
  • chown
1-9
248 && ! parse_with_separator (spec, dot, uid, gid, username, groupname)
! parse_with_s...me, groupname)Description
TRUEevaluated 8 times by 1 test
Evaluated by:
  • chown
FALSEevaluated 1 time by 1 test
Evaluated by:
  • chown
)
1-8
249 error_msg =
executed 8 times by 1 test: error_msg = ((void *)0) ;
Executed by:
  • chown
8
250 ((void *)0)
executed 8 times by 1 test: error_msg = ((void *)0) ;
Executed by:
  • chown
8
251 ;
executed 8 times by 1 test: error_msg = ((void *)0) ;
Executed by:
  • chown
8
252 }
executed 10 times by 1 test: end of block
Executed by:
  • chown
10
253-
254 return
executed 148 times by 2 tests: return error_msg;
Executed by:
  • chown
  • id
error_msg;
executed 148 times by 2 tests: return error_msg;
Executed by:
  • chown
  • id
148
255}-
Switch to Source codePreprocessed file

Generated by Squish Coco 4.1.2