sim: Fix a possible memory error in copyOutStatfsBuf.

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>
This commit is contained in:
Gabe Black
2020-05-25 04:24:11 -07:00
parent ce8a6a0cec
commit 1e2f4a8aa6

View 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