Skip to content

Commit d00aa1a

Browse files
mikhailnovstevegrubb
authored andcommitted
Fix DEREF_OF_NULL.RET.STAT in ausearch-match.c
Replace do-while loops with while loops to properly check for NULL before dereferencing pointers returned by ilist_get_cur() and slist_get_cur(). Svace report: 1) Return value of 'ilist_get_cur' is dereferenced at ausearch-match.c:138 without checking for NULL (CWE476) 2) Return value of 'slist_get_cur' is dereferenced at ausearch-match.c:223 without checking for NULL (CWE476) Co-authored-by: Z.AI GLM-5
1 parent 70b3576 commit d00aa1a

1 file changed

Lines changed: 12 additions & 9 deletions

File tree

src/ausearch-match.c

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -130,20 +130,21 @@ int match(llist *l)
130130

131131
list_first(l);
132132
n = list_get_cur(l);
133-
do {
133+
while (n) {
134134
int_node *in;
135135
ilist_first(event_type);
136136
in = ilist_get_cur(event_type);
137-
do {
137+
while (in) {
138138
if (in->num == n->type){
139139
found = 1;
140140
break;
141141
}
142-
} while((in =
143-
ilist_next(event_type)));
142+
in = ilist_next(event_type);
143+
}
144144
if (found)
145145
break;
146-
} while ((n = list_next(l)));
146+
n = list_next(l);
147+
}
147148
if (!found)
148149
return 0;
149150
}
@@ -160,7 +161,7 @@ int match(llist *l)
160161

161162
slist_first(sptr);
162163
sn=slist_get_cur(sptr);
163-
do {
164+
while (sn) {
164165
if (sn->str == NULL)
165166
return 0;
166167
if (strmatch(
@@ -169,7 +170,8 @@ int match(llist *l)
169170
found = 1;
170171
break;
171172
}
172-
} while ((sn=slist_next(sptr)));
173+
sn = slist_next(sptr);
174+
}
173175

174176
if (!found && l->s.cwd == NULL)
175177
return 0;
@@ -219,7 +221,7 @@ int match(llist *l)
219221

220222
slist_first(sptr);
221223
sn=slist_get_cur(sptr);
222-
do {
224+
while (sn) {
223225
if (sn->str == NULL)
224226
return 0;
225227
if (strmatch(
@@ -228,7 +230,8 @@ int match(llist *l)
228230
found = 1;
229231
break;
230232
}
231-
} while ((sn=slist_next(sptr)));
233+
sn = slist_next(sptr);
234+
}
232235
if (!found)
233236
return 0;
234237
}

0 commit comments

Comments
 (0)