Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 11 Jan 2018 23:58:41 +0000 (UTC)
From:      Alan Somers <asomers@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-11@freebsd.org
Subject:   svn commit: r327851 - stable/11/lib/libcam
Message-ID:  <201801112358.w0BNwfTv003502@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
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') {



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201801112358.w0BNwfTv003502>