diff options
author | Mike Snitzer <snitzer@redhat.com> | 2009-04-29 15:24:24 -0400 |
---|---|---|
committer | Mike Snitzer <snitzer@redhat.com> | 2009-04-29 15:24:24 -0400 |
commit | 3b3a6d968b6facb30e288cedd17ed08e73c37404 (patch) | |
tree | c56c74749b51e6b5a61efdaeef01a2f29cf1a68f | |
parent | aa6cb9ad2c555a50e512f31e379fdde2dc17c340 (diff) | |
download | multipath-tools-3b3a6d968b6facb30e288cedd17ed08e73c37404.tar.gz multipath-tools-3b3a6d968b6facb30e288cedd17ed08e73c37404.tar.bz2 multipath-tools-3b3a6d968b6facb30e288cedd17ed08e73c37404.zip |
avoid NULL pointers in discovery code
Both sysfs_pathinfo() and path_offline() could hit NULL pointers when
trying to dereference the newly acquired parent sysfs_device. By being
more defensive a crash I experienced in path_offline() is avoided.
Signed-off-by: Mike Snitzer <snitzer@redhat.com>
-rw-r--r-- | libmultipath/discovery.c | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/libmultipath/discovery.c b/libmultipath/discovery.c index 7d9f299..98d1618 100644 --- a/libmultipath/discovery.c +++ b/libmultipath/discovery.c @@ -589,11 +589,17 @@ path_offline (struct path * pp) condlog(1, "%s: failed to get sysfs information", pp->dev); return 1; } + parent = sysfs_device_get_parent(pp->sysdev); if (!parent) parent = pp->sysdev; - if (!strncmp(parent->kernel, "block",5)) + if (parent && !strncmp(parent->kernel, "block",5)) parent = sysfs_device_get_parent(parent); + if (!parent) { + condlog(1, "%s: failed to get parent", pp->dev); + return 1; + } + if (sysfs_get_state(parent, buff, SCSI_STATE_SIZE)) return 1; @@ -624,9 +630,12 @@ sysfs_pathinfo(struct path * pp) parent = sysfs_device_get_parent(pp->sysdev); if (!parent) parent = pp->sysdev; - - if (!strncmp(parent->kernel, "block",5)) + if (parent && !strncmp(parent->kernel, "block",5)) parent = sysfs_device_get_parent(parent); + if (!parent) { + condlog(1, "%s: failed to get parent", pp->dev); + return 1; + } if (!strncmp(pp->dev,"cciss",5)) strcpy(parent->subsystem,"cciss"); |