sim: Fix a possible memory error in copyOutStatfsBuf.
authorGabe Black <gabeblack@google.com>
Mon, 25 May 2020 11:24:11 +0000 (04:24 -0700)
committerGabe Black <gabeblack@google.com>
Tue, 26 May 2020 00:12:10 +0000 (00:12 +0000)
When memcpy-ing, we need to be sure not to read beyond the end of the
source, or write beyond the end of the target.

Change-Id: I3cf259bedce4c6e88aef47ef5379aab198338cb7
Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/29404
Reviewed-by: Jason Lowe-Power <power.jg@gmail.com>
Maintainer: Gabe Black <gabeblack@google.com>
Tested-by: kokoro <noreply+kokoro@google.com>
src/sim/syscall_emul.hh

index 55d30f3008a9028bebe20da7db19e6ed5799d9d5..247a98ca0f6ce286a2541fe93c4e45b044ffeadf 100644 (file)
@@ -677,7 +677,8 @@ copyOutStatfsBuf(PortProxy &mem, Addr addr,
     tgt->f_frsize = htog(host->f_frsize, bo);
 #endif
 #if defined(__linux__)
-    memcpy(&tgt->f_spare, &host->f_spare, sizeof(host->f_spare));
+    memcpy(&tgt->f_spare, &host->f_spare,
+            std::min(sizeof(host->f_spare), sizeof(tgt->f_spare)));
 #else
     /*
      * The fields are different sizes per OS. Don't bother with