summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorasomers <asomers@FreeBSD.org>2018-01-11 23:58:41 +0000
committerasomers <asomers@FreeBSD.org>2018-01-11 23:58:41 +0000
commitb55f0a5b31496ea10bd6e1163d13a1d8c26ca291 (patch)
tree1c6f37d7b5eddcd8e8f2805e668bd5a6be1b0d48 /lib
parent414d0525c2dfd498fb2e27e3521491f33fdcd6a2 (diff)
downloadFreeBSD-src-b55f0a5b31496ea10bd6e1163d13a1d8c26ca291.zip
FreeBSD-src-b55f0a5b31496ea10bd6e1163d13a1d8c26ca291.tar.gz
MFC r326646:
Fix a null-pointer dereference and a tautological check in cam_get_device Reported by: Coverity CID: 1017964 Sponsored by: Spectra Logic Corp Differential Revision: https://reviews.freebsd.org/D13184
Diffstat (limited to 'lib')
-rw-r--r--lib/libcam/camlib.c9
1 files changed, 7 insertions, 2 deletions
diff --git a/lib/libcam/camlib.c b/lib/libcam/camlib.c
index 3a6ccc1..d99a4c2 100644
--- a/lib/libcam/camlib.c
+++ b/lib/libcam/camlib.c
@@ -28,6 +28,7 @@ __FBSDID("$FreeBSD$");
#include <sys/types.h>
#include <sys/param.h>
+#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
@@ -130,6 +131,9 @@ cam_get_device(const char *path, char *dev_name, int devnamelen, int *unit)
* it so we don't hose the user's string.
*/
newpath = (char *)strdup(path);
+ if (newpath == NULL)
+ return (-1);
+
tmpstr = newpath;
/*
@@ -138,8 +142,9 @@ cam_get_device(const char *path, char *dev_name, int devnamelen, int *unit)
if (*tmpstr == '/') {
tmpstr2 = tmpstr;
tmpstr = strrchr(tmpstr2, '/');
- if ((tmpstr != NULL) && (*tmpstr != '\0'))
- tmpstr++;
+ /* We know that tmpstr2 contains a '/', so strrchr can't fail */
+ assert(tmpstr != NULL && *tmpstr != '\0');
+ tmpstr++;
}
if (*tmpstr == '\0') {
OpenPOWER on IntegriCloud