Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 9 Apr 2014 14:50:55 +0000 (UTC)
From:      Tycho Nightingale <tychon@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r264302 - head/usr.sbin/bhyve
Message-ID:  <201404091450.s39Eot5Q082384@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: tychon
Date: Wed Apr  9 14:50:55 2014
New Revision: 264302
URL: http://svnweb.freebsd.org/changeset/base/264302

Log:
  Constrain the amount of data returned to what is actually available
  not the size of the buffer.
  
  Approved by:	grehan (co-mentor)

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

Modified: head/usr.sbin/bhyve/pci_ahci.c
==============================================================================
--- head/usr.sbin/bhyve/pci_ahci.c	Wed Apr  9 13:35:52 2014	(r264301)
+++ head/usr.sbin/bhyve/pci_ahci.c	Wed Apr  9 14:50:55 2014	(r264302)
@@ -543,12 +543,14 @@ write_prdt(struct ahci_port *p, int slot
 	for (i = 0; i < hdr->prdtl && len; i++) {
 		uint8_t *ptr;
 		uint32_t dbcsz;
+		int sublen;
 
 		dbcsz = (prdt->dbc & DBCMASK) + 1;
 		ptr = paddr_guest2host(ahci_ctx(p->pr_sc), prdt->dba, dbcsz);
-		memcpy(ptr, from, dbcsz);
-		len -= dbcsz;
-		from += dbcsz;
+		sublen = len < dbcsz ? len : dbcsz;
+		memcpy(ptr, from, sublen);
+		len -= sublen;
+		from += sublen;
 		prdt++;
 	}
 	hdr->prdbc = size - len;



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