On Mon, 31 Aug 2015 08:48:03 -0600 Eric Blake <ebl...@redhat.com> wrote:
> On 08/31/2015 05:00 AM, Cornelia Huck wrote: > > From: "Jason J. Herne" <jjhe...@linux.vnet.ibm.com> > > > > Provide a dump-skeys qmp command to allow the end user to dump storage > > keys. This is useful for debugging problems with guest storage key support > > within Qemu and for guest operating system developers. > > > > Reviewed-by: Thomas Huth <th...@linux.vnet.ibm.com> > > Reviewed-by: David Hildenbrand <d...@linux.vnet.ibm.com> > > Signed-off-by: Jason J. Herne <jjhe...@linux.vnet.ibm.com> > > Signed-off-by: Cornelia Huck <cornelia.h...@de.ibm.com> > > --- > > hw/s390x/s390-skeys.c | 90 > > +++++++++++++++++++++++++++++++++++++++++++++++++-- > > monitor.c | 7 ++++ > > qapi-schema.json | 14 ++++++++ > > qmp-commands.hx | 25 ++++++++++++++ > > 4 files changed, 134 insertions(+), 2 deletions(-) > > > > > +static void write_keys(QEMUFile *f, uint8_t *keys, uint64_t startgfn, > > + uint64_t count, Error **errp) > > +{ > > + uint64_t curpage = startgfn; > > + uint64_t maxpage = curpage + count - 1; > > + const char *fmt = "page=%03" PRIx64 ": key(%d) => ACC=%X, FP=%d, > > REF=%d," > > + " ch=%d, reserved=%d\n"; > > + char buf[128]; > > + int len; > > + > > + for (; curpage <= maxpage; curpage++) { > > + uint8_t acc = (*keys & 0xF0) >> 4; > > + int fp = (*keys & 0x08); > > + int ref = (*keys & 0x04); > > + int ch = (*keys & 0x02); > > + int res = (*keys & 0x01); > > + > > + len = snprintf(buf, sizeof(buf), fmt, curpage, > > + *keys, acc, fp, ref, ch, res); > > + qemu_put_buffer(f, (uint8_t *)buf, len); > > While I can overlook the use of snprintf(), I still think you ought to > at least have assert(len < sizeof(buf)) here before the > qemu_put_buffer(), to ensure that future changes to fmt don't attempt to > print beyond the end of the fixed-width buffer. I'll just merge that in when sending the pull request. > > With an assert added, > Reviewed-by: Eric Blake <ebl...@redhat.com> > Thanks!