Date: Wed, 6 Dec 2017 23:24:11 +0000 (UTC) From: Alan Somers <asomers@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r326646 - head/lib/libcam Message-ID: <201712062324.vB6NOBUD073940@repo.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: asomers Date: Wed Dec 6 23:24:11 2017 New Revision: 326646 URL: https://svnweb.freebsd.org/changeset/base/326646 Log: Fix a null-pointer dereference and a tautological check in cam_get_device Reported by: Coverity CID: 1017964 MFC after: 3 weeks Sponsored by: Spectra Logic Corp Differential Revision: https://reviews.freebsd.org/D13184 Modified: head/lib/libcam/camlib.c Modified: head/lib/libcam/camlib.c ============================================================================== --- head/lib/libcam/camlib.c Wed Dec 6 23:05:22 2017 (r326645) +++ head/lib/libcam/camlib.c Wed Dec 6 23:24:11 2017 (r326646) @@ -30,6 +30,7 @@ __FBSDID("$FreeBSD$"); #include <sys/types.h> #include <sys/param.h> +#include <assert.h> #include <stdio.h> #include <stdlib.h> #include <stdint.h> @@ -132,6 +133,9 @@ cam_get_device(const char *path, char *dev_name, int d * it so we don't hose the user's string. */ newpath = (char *)strdup(path); + if (newpath == NULL) + return (-1); + tmpstr = newpath; /* @@ -140,8 +144,9 @@ cam_get_device(const char *path, char *dev_name, int d 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') {
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201712062324.vB6NOBUD073940>