mirror of
https://github.com/freebsd/freebsd-src
synced 2024-09-16 06:52:27 +00:00
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
This commit is contained in:
parent
762a7f4f5f
commit
0812ee3af2
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=326646
|
@ -30,6 +30,7 @@ __FBSDID("$FreeBSD$");
|
||||||
|
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <sys/param.h>
|
#include <sys/param.h>
|
||||||
|
#include <assert.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
@ -132,6 +133,9 @@ cam_get_device(const char *path, char *dev_name, int devnamelen, int *unit)
|
||||||
* it so we don't hose the user's string.
|
* it so we don't hose the user's string.
|
||||||
*/
|
*/
|
||||||
newpath = (char *)strdup(path);
|
newpath = (char *)strdup(path);
|
||||||
|
if (newpath == NULL)
|
||||||
|
return (-1);
|
||||||
|
|
||||||
tmpstr = newpath;
|
tmpstr = newpath;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -140,8 +144,9 @@ cam_get_device(const char *path, char *dev_name, int devnamelen, int *unit)
|
||||||
if (*tmpstr == '/') {
|
if (*tmpstr == '/') {
|
||||||
tmpstr2 = tmpstr;
|
tmpstr2 = tmpstr;
|
||||||
tmpstr = strrchr(tmpstr2, '/');
|
tmpstr = strrchr(tmpstr2, '/');
|
||||||
if ((tmpstr != NULL) && (*tmpstr != '\0'))
|
/* We know that tmpstr2 contains a '/', so strrchr can't fail */
|
||||||
tmpstr++;
|
assert(tmpstr != NULL && *tmpstr != '\0');
|
||||||
|
tmpstr++;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (*tmpstr == '\0') {
|
if (*tmpstr == '\0') {
|
||||||
|
|
Loading…
Reference in a new issue