svn commit: r327851 - stable/11/lib/libcam

Alan Somers asomers at FreeBSD.org
Thu Jan 11 23:58:42 UTC 2018


Author: asomers
Date: Thu Jan 11 23:58:41 2018
New Revision: 327851
URL: https://svnweb.freebsd.org/changeset/base/327851

Log:
  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

Modified:
  stable/11/lib/libcam/camlib.c
Directory Properties:
  stable/11/   (props changed)

Modified: stable/11/lib/libcam/camlib.c
==============================================================================
--- stable/11/lib/libcam/camlib.c	Thu Jan 11 23:57:55 2018	(r327850)
+++ stable/11/lib/libcam/camlib.c	Thu Jan 11 23:58:41 2018	(r327851)
@@ -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 d
 	 * 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 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') {


More information about the svn-src-stable-11 mailing list