aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGeorgy Yakovlev <gyakovlev@gentoo.org>2019-02-21 14:24:44 -0800
committerWilliam Hubbs <w.d.hubbs@gmail.com>2019-02-21 17:49:54 -0600
commit7478c104fc479067d71d191dccfa4cbf541311d8 (patch)
tree27d1bfdc1439924c5249f636a546288d0ab6d145
parent065b7ecc0d4ddd046cc235d60de20140db1a6fe8 (diff)
librc/librc-depend.c: fix NULL pointer dereference
In some cases deptree or depinfo can be NULL, check before dereferencing. Fixes https://github.com/OpenRC/openrc/issues/293 Fixes https://github.com/OpenRC/openrc/pulls/294 X-Gentoo-Bug: 659906 X-Gentoo-Bug-URL: https://bugs.gentoo.org/659906
-rw-r--r--src/librc/librc-depend.c17
1 files changed, 10 insertions, 7 deletions
diff --git a/src/librc/librc-depend.c b/src/librc/librc-depend.c
index 0d894e20..f010a072 100644
--- a/src/librc/librc-depend.c
+++ b/src/librc/librc-depend.c
@@ -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;
}
@@ -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;
}