Skip to content

Commit

Permalink
librc/librc-depend.c: fix NULL pointer dereference
Browse files Browse the repository at this point in the history
In some cases deptree or depinfo can be NULL, check
before dereferencing.

Fixes #293
Fixes https://github.com/OpenRC/openrc/pulls/294
X-Gentoo-Bug: 659906
X-Gentoo-Bug-URL: https://bugs.gentoo.org/659906
  • Loading branch information
gyakovlev authored and williamh committed Feb 21, 2019
1 parent 065b7ec commit 7478c10
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions src/librc/librc-depend.c
Expand Up @@ -84,10 +84,11 @@ static RC_DEPINFO *
get_depinfo(const RC_DEPTREE *deptree, const char *service)
{
RC_DEPINFO *di;

TAILQ_FOREACH(di, deptree, entries)
if (strcmp(di->service, service) == 0)
return di;
if (deptree) {
TAILQ_FOREACH(di, deptree, entries)
if (strcmp(di->service, service) == 0)
return di;
}
return NULL;
}

Expand All @@ -96,9 +97,11 @@ get_deptype(const RC_DEPINFO *depinfo, const char *type)
{
RC_DEPTYPE *dt;

TAILQ_FOREACH(dt, &depinfo->depends, entries)
if (strcmp(dt->type, type) == 0)
return dt;
if (depinfo) {
TAILQ_FOREACH(dt, &depinfo->depends, entries)
if (strcmp(dt->type, type) == 0)
return dt;
}
return NULL;
}

Expand Down

0 comments on commit 7478c10

Please sign in to comment.