Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 5 Jun 2019 23:37:50 +0000 (UTC)
From:      John Baldwin <jhb@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r348712 - head/usr.sbin/bhyve
Message-ID:  <201906052337.x55Nboku043965@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: jhb
Date: Wed Jun  5 23:37:50 2019
New Revision: 348712
URL: https://svnweb.freebsd.org/changeset/base/348712

Log:
  Use parse_integer to avoid sign extension.
  
  Coverity warned about gdb_write_mem sign extending the result of
  parse_byte shifted left by 24 bits when generating a 32-bit memory
  write value for MMIO.  Simplify the code by using parse_integer
  instead of unrolled parse_byte calls.
  
  CID:		1401600
  Reviewed by:	cem
  MFC after:	1 month
  Differential Revision:	https://reviews.freebsd.org/D20508

Modified:
  head/usr.sbin/bhyve/gdb.c

Modified: head/usr.sbin/bhyve/gdb.c
==============================================================================
--- head/usr.sbin/bhyve/gdb.c	Wed Jun  5 22:55:00 2019	(r348711)
+++ head/usr.sbin/bhyve/gdb.c	Wed Jun  5 23:37:50 2019	(r348712)
@@ -32,6 +32,7 @@ __FBSDID("$FreeBSD$");
 #ifndef WITHOUT_CAPSICUM
 #include <sys/capsicum.h>
 #endif
+#include <sys/endian.h>
 #include <sys/ioctl.h>
 #include <sys/mman.h>
 #include <sys/socket.h>
@@ -953,14 +954,10 @@ gdb_write_mem(const uint8_t *data, size_t len)
 					val = parse_byte(data);
 				} else if (gpa & 2 || todo == 2) {
 					bytes = 2;
-					val = parse_byte(data) |
-					    (parse_byte(data + 2) << 8);
+					val = be16toh(parse_integer(data, 4));
 				} else {
 					bytes = 4;
-					val = parse_byte(data) |
-					    (parse_byte(data + 2) << 8) |
-					    (parse_byte(data + 4) << 16) |
-					    (parse_byte(data + 6) << 24);
+					val = be32toh(parse_integer(data, 8));
 				}
 				error = write_mem(ctx, cur_vcpu, gpa, val,
 				    bytes);



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