svn commit: r300686 - head/sbin/camcontrol

Don Lewis truckman at FreeBSD.org
Wed May 25 15:49:30 UTC 2016


Author: truckman
Date: Wed May 25 15:49:29 2016
New Revision: 300686
URL: https://svnweb.freebsd.org/changeset/base/300686

Log:
  Fix a couple of Coverity Unintended sign extension sign extension
  defects.  When shifting an unsigned byte into the upper 8 bits of
  an int and the resulting value is greater than 0x7FFFFFF, the result
  will be sign extended when converting to a 64 bit unsigned long.
  Fix by casting to (uint64_t) before the shift.
  
  Reported by:	Coverity
  CID:		1356044, 1356045
  Reviewed by:	ken

Modified:
  head/sbin/camcontrol/camcontrol.c

Modified: head/sbin/camcontrol/camcontrol.c
==============================================================================
--- head/sbin/camcontrol/camcontrol.c	Wed May 25 15:43:01 2016	(r300685)
+++ head/sbin/camcontrol/camcontrol.c	Wed May 25 15:49:29 2016	(r300686)
@@ -5188,7 +5188,7 @@ get_ata_status(struct cam_device *dev, u
 				  desc->count_7_0;
 			*lba = ((uint64_t)desc->lba_47_40 << 40) |
 			       ((uint64_t)desc->lba_39_32 << 32) |
-			       (desc->lba_31_24 << 24) |
+			       ((uint64_t)desc->lba_31_24 << 24) |
 			       (desc->lba_23_16 << 16) |
 			       (desc->lba_15_8  <<  8) |
 			        desc->lba_7_0;
@@ -5249,7 +5249,7 @@ get_ata_status(struct cam_device *dev, u
 		       (res->lba_low);
 		if (res->flags & CAM_ATAIO_48BIT) {
 			*count |= (res->sector_count_exp << 8);
-			*lba |= (res->lba_low_exp << 24) |
+			*lba |= ((uint64_t)res->lba_low_exp << 24) |
 				((uint64_t)res->lba_mid_exp << 32) |
 				((uint64_t)res->lba_high_exp << 40);
 		} else {


More information about the svn-src-head mailing list