OpenCoverage

match.c

Absolute File Name:/home/opencoverage/opencoverage/guest-scripts/openssh/src/match.c
Source codeSwitch to Preprocessed file
LineSourceCount
1/* $OpenBSD: match.c,v 1.38 2018/07/04 13:49:31 djm Exp $ */-
2/*-
3 * Author: Tatu Ylonen <ylo@cs.hut.fi>-
4 * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland-
5 * All rights reserved-
6 * Simple pattern matching, with '*' and '?' as wildcards.-
7 *-
8 * As far as I am concerned, the code I have written for this software-
9 * can be used freely for any purpose. Any derived versions of this-
10 * software must be clearly marked as such, and if the derived work is-
11 * incompatible with the protocol description in the RFC file, it must be-
12 * called by a name other than "ssh" or "Secure Shell".-
13 */-
14/*-
15 * Copyright (c) 2000 Markus Friedl. All rights reserved.-
16 *-
17 * Redistribution and use in source and binary forms, with or without-
18 * modification, are permitted provided that the following conditions-
19 * are met:-
20 * 1. Redistributions of source code must retain the above copyright-
21 * notice, this list of conditions and the following disclaimer.-
22 * 2. Redistributions in binary form must reproduce the above copyright-
23 * notice, this list of conditions and the following disclaimer in the-
24 * documentation and/or other materials provided with the distribution.-
25 *-
26 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR-
27 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES-
28 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.-
29 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,-
30 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT-
31 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,-
32 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY-
33 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT-
34 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF-
35 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.-
36 */-
37-
38#include "includes.h"-
39-
40#include <sys/types.h>-
41-
42#include <ctype.h>-
43#include <stdlib.h>-
44#include <string.h>-
45#include <stdio.h>-
46-
47#include "xmalloc.h"-
48#include "match.h"-
49#include "misc.h"-
50-
51/*-
52 * Returns true if the given string matches the pattern (which may contain ?-
53 * and * as wildcards), and zero if it does not match.-
54 */-
55-
56int-
57match_pattern(const char *s, const char *pattern)-
58{-
59 for (;;) {-
60 /* If at end of pattern, accept if also at end of string. */-
61 if (!*pattern)
!*patternDescription
TRUEevaluated 162 times by 2 tests
Evaluated by:
  • test_hostkeys
  • test_match
FALSEevaluated 16225 times by 3 tests
Evaluated by:
  • test_hostkeys
  • test_kex
  • test_match
162-16225
62 return !*s;
executed 162 times by 2 tests: return !*s;
Executed by:
  • test_hostkeys
  • test_match
162
63-
64 if (*pattern == '*') {
*pattern == '*'Description
TRUEevaluated 250 times by 3 tests
Evaluated by:
  • test_hostkeys
  • test_kex
  • test_match
FALSEevaluated 15975 times by 3 tests
Evaluated by:
  • test_hostkeys
  • test_kex
  • test_match
250-15975
65 /* Skip the asterisk. */-
66 pattern++;-
67-
68 /* If at end of pattern, accept immediately. */-
69 if (!*pattern)
!*patternDescription
TRUEevaluated 117 times by 3 tests
Evaluated by:
  • test_hostkeys
  • test_kex
  • test_match
FALSEevaluated 133 times by 2 tests
Evaluated by:
  • test_hostkeys
  • test_match
117-133
70 return 1;
executed 117 times by 3 tests: return 1;
Executed by:
  • test_hostkeys
  • test_kex
  • test_match
117
71-
72 /* If next character in pattern is known, optimize. */-
73 if (*pattern != '?' && *pattern != '*') {
*pattern != '?'Description
TRUEevaluated 133 times by 2 tests
Evaluated by:
  • test_hostkeys
  • test_match
FALSEnever evaluated
*pattern != '*'Description
TRUEevaluated 132 times by 2 tests
Evaluated by:
  • test_hostkeys
  • test_match
FALSEevaluated 1 time by 1 test
Evaluated by:
  • test_match
0-133
74 /*-
75 * Look instances of the next character in-
76 * pattern, and try to match starting from-
77 * those.-
78 */-
79 for (; *s; s++)
*sDescription
TRUEevaluated 1664 times by 2 tests
Evaluated by:
  • test_hostkeys
  • test_match
FALSEevaluated 91 times by 2 tests
Evaluated by:
  • test_hostkeys
  • test_match
91-1664
80 if (*s == *pattern &&
*s == *patternDescription
TRUEevaluated 198 times by 2 tests
Evaluated by:
  • test_hostkeys
  • test_match
FALSEevaluated 1466 times by 2 tests
Evaluated by:
  • test_hostkeys
  • test_match
198-1466
81 match_pattern(s + 1, pattern + 1))
match_pattern(..., pattern + 1)Description
TRUEevaluated 41 times by 2 tests
Evaluated by:
  • test_hostkeys
  • test_match
FALSEevaluated 157 times by 2 tests
Evaluated by:
  • test_hostkeys
  • test_match
41-157
82 return 1;
executed 41 times by 2 tests: return 1;
Executed by:
  • test_hostkeys
  • test_match
41
83 /* Failed. */-
84 return 0;
executed 91 times by 2 tests: return 0;
Executed by:
  • test_hostkeys
  • test_match
91
85 }-
86 /*-
87 * Move ahead one character at a time and try to-
88 * match at each position.-
89 */-
90 for (; *s; s++)
*sDescription
TRUEevaluated 1 time by 1 test
Evaluated by:
  • test_match
FALSEnever evaluated
0-1
91 if (match_pattern(s, pattern))
match_pattern(s, pattern)Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • test_match
FALSEnever evaluated
0-1
92 return 1;
executed 1 time by 1 test: return 1;
Executed by:
  • test_match
1
93 /* Failed. */-
94 return 0;
never executed: return 0;
0
95 }-
96 /*-
97 * There must be at least one more character in the string.-
98 * If we are at the end, fail.-
99 */-
100 if (!*s)
!*sDescription
TRUEevaluated 8 times by 1 test
Evaluated by:
  • test_match
FALSEevaluated 15967 times by 3 tests
Evaluated by:
  • test_hostkeys
  • test_kex
  • test_match
8-15967
101 return 0;
executed 8 times by 1 test: return 0;
Executed by:
  • test_match
8
102-
103 /* Check if the next character of the string is acceptable. */-
104 if (*pattern != '?' && *pattern != *s)
*pattern != '?'Description
TRUEevaluated 15962 times by 3 tests
Evaluated by:
  • test_hostkeys
  • test_kex
  • test_match
FALSEevaluated 5 times by 1 test
Evaluated by:
  • test_match
*pattern != *sDescription
TRUEevaluated 2154 times by 3 tests
Evaluated by:
  • test_hostkeys
  • test_kex
  • test_match
FALSEevaluated 13808 times by 3 tests
Evaluated by:
  • test_hostkeys
  • test_kex
  • test_match
5-15962
105 return 0;
executed 2154 times by 3 tests: return 0;
Executed by:
  • test_hostkeys
  • test_kex
  • test_match
2154
106-
107 /* Move to the next character, both in string and in pattern. */-
108 s++;-
109 pattern++;-
110 }
executed 13813 times by 3 tests: end of block
Executed by:
  • test_hostkeys
  • test_kex
  • test_match
13813
111 /* NOTREACHED */-
112}
never executed: end of block
0
113-
114/*-
115 * Tries to match the string against the-
116 * comma-separated sequence of subpatterns (each possibly preceded by ! to-
117 * indicate negation). Returns -1 if negation matches, 1 if there is-
118 * a positive match, 0 if there is no match at all.-
119 */-
120int-
121match_pattern_list(const char *string, const char *pattern, int dolower)-
122{-
123 char sub[1024];-
124 int negated;-
125 int got_positive;-
126 u_int i, subi, len = strlen(pattern);-
127-
128 got_positive = 0;-
129 for (i = 0; i < len;) {
i < lenDescription
TRUEevaluated 2356 times by 3 tests
Evaluated by:
  • test_hostkeys
  • test_kex
  • test_match
FALSEevaluated 1136 times by 3 tests
Evaluated by:
  • test_hostkeys
  • test_kex
  • test_match
1136-2356
130 /* Check if the subpattern is negated. */-
131 if (pattern[i] == '!') {
pattern[i] == '!'Description
TRUEevaluated 16 times by 1 test
Evaluated by:
  • test_match
FALSEevaluated 2340 times by 3 tests
Evaluated by:
  • test_hostkeys
  • test_kex
  • test_match
16-2340
132 negated = 1;-
133 i++;-
134 } else
executed 16 times by 1 test: end of block
Executed by:
  • test_match
16
135 negated = 0;
executed 2340 times by 3 tests: negated = 0;
Executed by:
  • test_hostkeys
  • test_kex
  • test_match
2340
136-
137 /*-
138 * Extract the subpattern up to a comma or end. Convert the-
139 * subpattern to lowercase.-
140 */-
141 for (subi = 0;-
142 i < len && subi < sizeof(sub) - 1 && pattern[i] != ',';
i < lenDescription
TRUEevaluated 30155 times by 3 tests
Evaluated by:
  • test_hostkeys
  • test_kex
  • test_match
FALSEevaluated 1139 times by 3 tests
Evaluated by:
  • test_hostkeys
  • test_kex
  • test_match
subi < sizeof(sub) - 1Description
TRUEevaluated 30155 times by 3 tests
Evaluated by:
  • test_hostkeys
  • test_kex
  • test_match
FALSEnever evaluated
pattern[i] != ','Description
TRUEevaluated 28938 times by 3 tests
Evaluated by:
  • test_hostkeys
  • test_kex
  • test_match
FALSEevaluated 1217 times by 3 tests
Evaluated by:
  • test_hostkeys
  • test_kex
  • test_match
0-30155
143 subi++, i++)-
144 sub[subi] = dolower && isupper((u_char)pattern[i]) ?
executed 28938 times by 3 tests: sub[subi] = dolower && ((*__ctype_b_loc ())[(int) (( (u_char)pattern[i] ))] & (unsigned short int) _ISupper) ? (__extension__ ({ int __res; if (sizeof ( (u_char)pattern[i] ) > 1) { if (__builtin_constant_p ( (u_char)pattern[i] )) { int __c = ( (u_char)pattern[i] ); __res = __c < -128 || __c > 255 ? __c : (*__ctype_tolower_loc ())[__c]; } else __res = tolower ( (u_char)pattern[i] ); } else __res = (*__ctype_tolower_loc ())[(int) ( (u_char)pattern[i] )]; __res; })) : pattern[i];
Executed by:
  • test_hostkeys
  • test_kex
  • test_match
dolowerDescription
TRUEevaluated 13500 times by 2 tests
Evaluated by:
  • test_hostkeys
  • test_match
FALSEevaluated 15438 times by 2 tests
Evaluated by:
  • test_kex
  • test_match
((*__ctype_b_l...int) _ISupper)Description
TRUEevaluated 3 times by 1 test
Evaluated by:
  • test_match
FALSEevaluated 13497 times by 2 tests
Evaluated by:
  • test_hostkeys
  • test_match
3-28938
145 tolower((u_char)pattern[i]) : pattern[i];
executed 28938 times by 3 tests: sub[subi] = dolower && ((*__ctype_b_loc ())[(int) (( (u_char)pattern[i] ))] & (unsigned short int) _ISupper) ? (__extension__ ({ int __res; if (sizeof ( (u_char)pattern[i] ) > 1) { if (__builtin_constant_p ( (u_char)pattern[i] )) { int __c = ( (u_char)pattern[i] ); __res = __c < -128 || __c > 255 ? __c : (*__ctype_tolower_loc ())[__c]; } else __res = tolower ( (u_char)pattern[i] ); } else __res = (*__ctype_tolower_loc ())[(int) ( (u_char)pattern[i] )]; __res; })) : pattern[i];
Executed by:
  • test_hostkeys
  • test_kex
  • test_match
never executed: end of block
never executed: __res = tolower ( (u_char)pattern[i] );
executed 3 times by 1 test: __res = (*__ctype_tolower_loc ())[(int) ( (u_char)pattern[i] )];
Executed by:
  • test_match
sizeof ( (u_ch...ttern[i] ) > 1Description
TRUEnever evaluated
FALSEevaluated 3 times by 1 test
Evaluated by:
  • test_match
__builtin_cons...r)pattern[i] )Description
TRUEnever evaluated
FALSEnever evaluated
__c < -128Description
TRUEnever evaluated
FALSEnever evaluated
__c > 255Description
TRUEnever evaluated
FALSEnever evaluated
0-28938
146 /* If subpattern too long, return failure (no match). */-
147 if (subi >= sizeof(sub) - 1)
subi >= sizeof(sub) - 1Description
TRUEnever evaluated
FALSEevaluated 2356 times by 3 tests
Evaluated by:
  • test_hostkeys
  • test_kex
  • test_match
0-2356
148 return 0;
never executed: return 0;
0
149-
150 /* If the subpattern was terminated by a comma, then skip it. */-
151 if (i < len && pattern[i] == ',')
i < lenDescription
TRUEevaluated 1217 times by 3 tests
Evaluated by:
  • test_hostkeys
  • test_kex
  • test_match
FALSEevaluated 1139 times by 3 tests
Evaluated by:
  • test_hostkeys
  • test_kex
  • test_match
pattern[i] == ','Description
TRUEevaluated 1217 times by 3 tests
Evaluated by:
  • test_hostkeys
  • test_kex
  • test_match
FALSEnever evaluated
0-1217
152 i++;
executed 1217 times by 3 tests: i++;
Executed by:
  • test_hostkeys
  • test_kex
  • test_match
1217
153-
154 /* Null-terminate the subpattern. */-
155 sub[subi] = '\0';-
156-
157 /* Try to match the subpattern against the string. */-
158 if (match_pattern(string, sub)) {
match_pattern(string, sub)Description
TRUEevaluated 264 times by 3 tests
Evaluated by:
  • test_hostkeys
  • test_kex
  • test_match
FALSEevaluated 2092 times by 3 tests
Evaluated by:
  • test_hostkeys
  • test_kex
  • test_match
264-2092
159 if (negated)
negatedDescription
TRUEevaluated 12 times by 1 test
Evaluated by:
  • test_match
FALSEevaluated 252 times by 3 tests
Evaluated by:
  • test_hostkeys
  • test_kex
  • test_match
12-252
160 return -1; /* Negative */
executed 12 times by 1 test: return -1;
Executed by:
  • test_match
12
161 else-
162 got_positive = 1; /* Positive */
executed 252 times by 3 tests: got_positive = 1;
Executed by:
  • test_hostkeys
  • test_kex
  • test_match
252
163 }-
164 }
executed 2344 times by 3 tests: end of block
Executed by:
  • test_hostkeys
  • test_kex
  • test_match
2344
165-
166 /*-
167 * Return success if got a positive match. If there was a negative-
168 * match, we have already returned -1 and never get here.-
169 */-
170 return got_positive;
executed 1136 times by 3 tests: return got_positive;
Executed by:
  • test_hostkeys
  • test_kex
  • test_match
1136
171}-
172-
173/*-
174 * Tries to match the host name (which must be in all lowercase) against the-
175 * comma-separated sequence of subpatterns (each possibly preceded by ! to-
176 * indicate negation). Returns -1 if negation matches, 1 if there is-
177 * a positive match, 0 if there is no match at all.-
178 */-
179int-
180match_hostname(const char *host, const char *pattern)-
181{-
182 char *hostcopy = xstrdup(host);-
183 int r;-
184-
185 lowercase(hostcopy);-
186 r = match_pattern_list(hostcopy, pattern, 1);-
187 free(hostcopy);-
188 return r;
executed 520 times by 1 test: return r;
Executed by:
  • test_hostkeys
520
189}-
190-
191/*-
192 * returns 0 if we get a negative match for the hostname or the ip-
193 * or if we get no match at all. returns -1 on error, or 1 on-
194 * successful match.-
195 */-
196int-
197match_host_and_ip(const char *host, const char *ipaddr,-
198 const char *patterns)-
199{-
200 int mhost, mip;-
201-
202 if ((mip = addr_match_list(ipaddr, patterns)) == -2)
(mip = addr_ma...tterns)) == -2Description
TRUEnever evaluated
FALSEnever evaluated
0
203 return -1; /* error in ipaddr match */
never executed: return -1;
0
204 else if (host == NULL || ipaddr == NULL || mip == -1)
host == ((void *)0)Description
TRUEnever evaluated
FALSEnever evaluated
ipaddr == ((void *)0)Description
TRUEnever evaluated
FALSEnever evaluated
mip == -1Description
TRUEnever evaluated
FALSEnever evaluated
0
205 return 0; /* negative ip address match, or testing pattern */
never executed: return 0;
0
206-
207 /* negative hostname match */-
208 if ((mhost = match_hostname(host, patterns)) == -1)
(mhost = match...tterns)) == -1Description
TRUEnever evaluated
FALSEnever evaluated
0
209 return 0;
never executed: return 0;
0
210 /* no match at all */-
211 if (mhost == 0 && mip == 0)
mhost == 0Description
TRUEnever evaluated
FALSEnever evaluated
mip == 0Description
TRUEnever evaluated
FALSEnever evaluated
0
212 return 0;
never executed: return 0;
0
213 return 1;
never executed: return 1;
0
214}-
215-
216/*-
217 * Match user, user@host_or_ip, user@host_or_ip_list against pattern.-
218 * If user, host and ipaddr are all NULL then validate pattern/-
219 * Returns -1 on invalid pattern, 0 on no match, 1 on match.-
220 */-
221int-
222match_user(const char *user, const char *host, const char *ipaddr,-
223 const char *pattern)-
224{-
225 char *p, *pat;-
226 int ret;-
227-
228 /* test mode */-
229 if (user == NULL && host == NULL && ipaddr == NULL) {
user == ((void *)0)Description
TRUEnever evaluated
FALSEnever evaluated
host == ((void *)0)Description
TRUEnever evaluated
FALSEnever evaluated
ipaddr == ((void *)0)Description
TRUEnever evaluated
FALSEnever evaluated
0
230 if ((p = strchr(pattern, '@')) != NULL &&
(p = (__extens...!= ((void *)0)Description
TRUEnever evaluated
FALSEnever evaluated
__builtin_constant_p ( '@' )Description
TRUEnever evaluated
FALSEnever evaluated
!__builtin_con..._p ( pattern )Description
TRUEnever evaluated
FALSEnever evaluated
( '@' ) == '\0'Description
TRUEnever evaluated
FALSEnever evaluated
0
231 match_host_and_ip(NULL, NULL, p + 1) < 0)
match_host_and...) , p + 1) < 0Description
TRUEnever evaluated
FALSEnever evaluated
0
232 return -1;
never executed: return -1;
0
233 return 0;
never executed: return 0;
0
234 }-
235-
236 if ((p = strchr(pattern,'@')) == NULL)
(p = (__extens...== ((void *)0)Description
TRUEnever evaluated
FALSEnever evaluated
__builtin_constant_p ( '@' )Description
TRUEnever evaluated
FALSEnever evaluated
!__builtin_con..._p ( pattern )Description
TRUEnever evaluated
FALSEnever evaluated
( '@' ) == '\0'Description
TRUEnever evaluated
FALSEnever evaluated
0
237 return match_pattern(user, pattern);
never executed: return match_pattern(user, pattern);
0
238-
239 pat = xstrdup(pattern);-
240 p = strchr(pat, '@');
__builtin_constant_p ( '@' )Description
TRUEnever evaluated
FALSEnever evaluated
!__builtin_constant_p ( pat )Description
TRUEnever evaluated
FALSEnever evaluated
( '@' ) == '\0'Description
TRUEnever evaluated
FALSEnever evaluated
0
241 *p++ = '\0';-
242-
243 if ((ret = match_pattern(user, pat)) == 1)
(ret = match_p...er, pat)) == 1Description
TRUEnever evaluated
FALSEnever evaluated
0
244 ret = match_host_and_ip(host, ipaddr, p);
never executed: ret = match_host_and_ip(host, ipaddr, p);
0
245 free(pat);-
246-
247 return ret;
never executed: return ret;
0
248}-
249-
250/*-
251 * Returns first item from client-list that is also supported by server-list,-
252 * caller must free the returned string.-
253 */-
254#define MAX_PROP 40-
255#define SEP ","-
256char *-
257match_list(const char *client, const char *server, u_int *next)-
258{-
259 char *sproposals[MAX_PROP];-
260 char *c, *s, *p, *ret, *cp, *sp;-
261 int i, j, nproposals;-
262-
263 c = cp = xstrdup(client);-
264 s = sp = xstrdup(server);-
265-
266 for ((p = strsep(&sp, SEP)), i=0; p && *p != '\0';
pDescription
TRUEevaluated 5920 times by 1 test
Evaluated by:
  • test_kex
FALSEevaluated 2080 times by 1 test
Evaluated by:
  • test_kex
*p != '\0'Description
TRUEevaluated 5920 times by 1 test
Evaluated by:
  • test_kex
FALSEnever evaluated
0-5920
267 (p = strsep(&sp, SEP)), i++) {-
268 if (i < MAX_PROP)
i < 40Description
TRUEevaluated 5920 times by 1 test
Evaluated by:
  • test_kex
FALSEnever evaluated
0-5920
269 sproposals[i] = p;
executed 5920 times by 1 test: sproposals[i] = p;
Executed by:
  • test_kex
5920
270 else-
271 break;
never executed: break;
0
272 }-
273 nproposals = i;-
274-
275 for ((p = strsep(&cp, SEP)), i=0; p && *p != '\0';
pDescription
TRUEevaluated 2080 times by 1 test
Evaluated by:
  • test_kex
FALSEevaluated 160 times by 1 test
Evaluated by:
  • test_kex
*p != '\0'Description
TRUEevaluated 2080 times by 1 test
Evaluated by:
  • test_kex
FALSEnever evaluated
0-2080
276 (p = strsep(&cp, SEP)), i++) {-
277 for (j = 0; j < nproposals; j++) {
j < nproposalsDescription
TRUEevaluated 2080 times by 1 test
Evaluated by:
  • test_kex
FALSEevaluated 160 times by 1 test
Evaluated by:
  • test_kex
160-2080
278 if (strcmp(p, sproposals[j]) == 0) {
never executed: __result = (((const unsigned char *) (const char *) ( p ))[3] - __s2[3]);
never executed: end of block
never executed: end of block
never executed: __result = (((const unsigned char *) (const char *) ( sproposals[j] ))[3] - __s2[3]);
never executed: end of block
never executed: end of block
__extension__ ... )))); }) == 0Description
TRUEevaluated 1920 times by 1 test
Evaluated by:
  • test_kex
FALSEevaluated 160 times by 1 test
Evaluated by:
  • test_kex
__s1_len > 0Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s1_len > 1Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s1_len > 2Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s2_len > 0Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s2_len > 1Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s2_len > 2Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
0-1920
279 ret = xstrdup(p);-
280 if (next != NULL)
next != ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 1920 times by 1 test
Evaluated by:
  • test_kex
0-1920
281 *next = (cp == NULL) ?
never executed: *next = (cp == ((void *)0) ) ? strlen(c) : (u_int)(cp - c);
(cp == ((void *)0) )Description
TRUEnever evaluated
FALSEnever evaluated
0
282 strlen(c) : (u_int)(cp - c);
never executed: *next = (cp == ((void *)0) ) ? strlen(c) : (u_int)(cp - c);
0
283 free(c);-
284 free(s);-
285 return ret;
executed 1920 times by 1 test: return ret;
Executed by:
  • test_kex
1920
286 }-
287 }
executed 160 times by 1 test: end of block
Executed by:
  • test_kex
160
288 }
executed 160 times by 1 test: end of block
Executed by:
  • test_kex
160
289 if (next != NULL)
next != ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 160 times by 1 test
Evaluated by:
  • test_kex
0-160
290 *next = strlen(c);
never executed: *next = strlen(c);
0
291 free(c);-
292 free(s);-
293 return NULL;
executed 160 times by 1 test: return ((void *)0) ;
Executed by:
  • test_kex
160
294}-
295-
296/*-
297 * Filter proposal using pattern-list filter.-
298 * "blacklist" determines sense of filter:-
299 * non-zero indicates that items matching filter should be excluded.-
300 * zero indicates that only items matching filter should be included.-
301 * returns NULL on allocation error, otherwise caller must free result.-
302 */-
303static char *-
304filter_list(const char *proposal, const char *filter, int blacklist)-
305{-
306 size_t len = strlen(proposal) + 1;-
307 char *fix_prop = malloc(len);-
308 char *orig_prop = strdup(proposal);
never executed: __retval = (char *) memcpy (__retval, proposal , __len);
__retval != ((void *)0)Description
TRUEnever evaluated
FALSEnever evaluated
((const char *... ))[0] == '\0'Description
TRUEnever evaluated
FALSEnever evaluated
__builtin_cons...p ( proposal )Description
TRUEnever evaluated
FALSEevaluated 10 times by 1 test
Evaluated by:
  • test_match
((size_t)(cons...oposal ) == 1)Description
TRUEnever evaluated
FALSEnever evaluated
0-10
309 char *cp, *tmp;-
310 int r;-
311-
312 if (fix_prop == NULL || orig_prop == NULL) {
fix_prop == ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 10 times by 1 test
Evaluated by:
  • test_match
orig_prop == ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 10 times by 1 test
Evaluated by:
  • test_match
0-10
313 free(orig_prop);-
314 free(fix_prop);-
315 return NULL;
never executed: return ((void *)0) ;
0
316 }-
317-
318 tmp = orig_prop;-
319 *fix_prop = '\0';-
320 while ((cp = strsep(&tmp, ",")) != NULL) {
(cp = __extens...!= ((void *)0)Description
TRUEevaluated 28 times by 1 test
Evaluated by:
  • test_match
FALSEevaluated 10 times by 1 test
Evaluated by:
  • test_match
10-28
321 r = match_pattern_list(cp, filter, 0);-
322 if ((blacklist && r != 1) || (!blacklist && r == 1)) {
blacklistDescription
TRUEevaluated 28 times by 1 test
Evaluated by:
  • test_match
FALSEnever evaluated
r != 1Description
TRUEevaluated 14 times by 1 test
Evaluated by:
  • test_match
FALSEevaluated 14 times by 1 test
Evaluated by:
  • test_match
!blacklistDescription
TRUEnever evaluated
FALSEevaluated 14 times by 1 test
Evaluated by:
  • test_match
r == 1Description
TRUEnever evaluated
FALSEnever evaluated
0-28
323 if (*fix_prop != '\0')
*fix_prop != '\0'Description
TRUEevaluated 5 times by 1 test
Evaluated by:
  • test_match
FALSEevaluated 9 times by 1 test
Evaluated by:
  • test_match
5-9
324 strlcat(fix_prop, ",", len);
executed 5 times by 1 test: strlcat(fix_prop, ",", len);
Executed by:
  • test_match
5
325 strlcat(fix_prop, cp, len);-
326 }
executed 14 times by 1 test: end of block
Executed by:
  • test_match
14
327 }
executed 28 times by 1 test: end of block
Executed by:
  • test_match
28
328 free(orig_prop);-
329 return fix_prop;
executed 10 times by 1 test: return fix_prop;
Executed by:
  • test_match
10
330}-
331-
332/*-
333 * Filters a comma-separated list of strings, excluding any entry matching-
334 * the 'filter' pattern list. Caller must free returned string.-
335 */-
336char *-
337match_filter_blacklist(const char *proposal, const char *filter)-
338{-
339 return filter_list(proposal, filter, 1);
executed 10 times by 1 test: return filter_list(proposal, filter, 1);
Executed by:
  • test_match
10
340}-
341-
342/*-
343 * Filters a comma-separated list of strings, including only entries matching-
344 * the 'filter' pattern list. Caller must free returned string.-
345 */-
346char *-
347match_filter_whitelist(const char *proposal, const char *filter)-
348{-
349 return filter_list(proposal, filter, 0);
never executed: return filter_list(proposal, filter, 0);
0
350}-
Source codeSwitch to Preprocessed file

Generated by Squish Coco 4.2.2