fdtgrep: Deal with NULL data passed to check_type_include()

Since the parameter can be NULL we must be careful not to dereference it
in this case.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reported-by: Coverity (CID: 163250)
Fixes: 1043d0a0 (fdt: Add fdtgrep tool)
master
Simon Glass 7 years ago committed by Tom Rini
parent 66a1b30d14
commit 9672515319
  1. 25
      tools/fdtgrep.c

@ -522,18 +522,21 @@ static int check_type_include(void *priv, int type, const char *data, int size)
* return 1 at the first match. For exclusive conditions, we must * return 1 at the first match. For exclusive conditions, we must
* check that there are no matches. * check that there are no matches.
*/ */
for (val = disp->value_head; val; val = val->next) { if (data) {
if (!(type & val->type)) for (val = disp->value_head; val; val = val->next) {
continue; if (!(type & val->type))
match = fdt_stringlist_contains(data, size, val->string); continue;
debug(" - val->type=%x, str='%s', match=%d\n", match = fdt_stringlist_contains(data, size,
val->type, val->string, match); val->string);
if (match && val->include) { debug(" - val->type=%x, str='%s', match=%d\n",
debug(" - match inc %s\n", val->string); val->type, val->string, match);
return 1; if (match && val->include) {
debug(" - match inc %s\n", val->string);
return 1;
}
if (match)
none_match &= ~val->type;
} }
if (match)
none_match &= ~val->type;
} }
/* /*

Loading…
Cancel
Save