Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 22 Mar 2018 06:31:05 +0000 (UTC)
From:      Ravi Pokala <rpokala@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r331345 - head/sys/dev/jedec_dimm
Message-ID:  <201803220631.w2M6V5GH072839@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: rpokala
Date: Thu Mar 22 06:31:05 2018
New Revision: 331345
URL: https://svnweb.freebsd.org/changeset/base/331345

Log:
  jedec_dimm: Use correct string length when populating sc->slotid_str
  
  Don't limit the copy to the size of the target string *pointer* (always
  4 on 32-bit / 8 on 64-bit). Instead, just use strdup().
  
  Reported by:	Coverity
  CID:		1386912
  Reviewed by:	cem, imp
  MFC after:	1 week

Modified:
  head/sys/dev/jedec_dimm/jedec_dimm.c

Modified: head/sys/dev/jedec_dimm/jedec_dimm.c
==============================================================================
--- head/sys/dev/jedec_dimm/jedec_dimm.c	Thu Mar 22 05:26:27 2018	(r331344)
+++ head/sys/dev/jedec_dimm/jedec_dimm.c	Thu Mar 22 06:31:05 2018	(r331345)
@@ -341,10 +341,7 @@ jedec_dimm_attach(device_t dev)
 	if (resource_string_value(device_get_name(dev), device_get_unit(dev),
 	    "slotid", &slotid_str) == 0) {
 		if (slotid_str != NULL) {
-			sc->slotid_str = malloc(strlen(slotid_str) + 1,
-			    M_DEVBUF, (M_WAITOK | M_ZERO));
-			strlcpy(sc->slotid_str, slotid_str,
-			    sizeof(sc->slotid_str));
+			sc->slotid_str = strdup(slotid_str, M_DEVBUF);
 			SYSCTL_ADD_STRING(ctx, children, OID_AUTO, "slotid",
 			    CTLFLAG_RD | CTLFLAG_MPSAFE, sc->slotid_str, 0,
 			    "DIMM Slot Identifier");



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