From b3af1bc9d21e6bec7dfd283d91b465c9f815b6d6 Mon Sep 17 00:00:00 2001 From: "Dr. David Alan Gilbert" Date: Thu, 21 May 2015 13:24:11 +0100 Subject: Add qemu_get_counted_string to read a string prefixed by a count byte and use it in loadvm_state and ram_load. Where ever it's used, check the return and error if it failed. Minor: ram_load was using a 257 byte array for its string, the maximum length is 255 bytes + 0 terminator, so fix to 256 Signed-off-by: Dr. David Alan Gilbert Reviewed-by: Amit Shah Reviewed-by: David Gibson Reviewed-by: Juan Quintela Signed-off-by: Juan Quintela --- migration/qemu-file.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'migration/qemu-file.c') diff --git a/migration/qemu-file.c b/migration/qemu-file.c index 2750365a7e..0ef543a6df 100644 --- a/migration/qemu-file.c +++ b/migration/qemu-file.c @@ -585,3 +585,20 @@ int qemu_put_qemu_file(QEMUFile *f_des, QEMUFile *f_src) } return len; } + +/* + * Get a string whose length is determined by a single preceding byte + * A preallocated 256 byte buffer must be passed in. + * Returns: len on success and a 0 terminated string in the buffer + * else 0 + * (Note a 0 length string will return 0 either way) + */ +size_t qemu_get_counted_string(QEMUFile *f, char buf[256]) +{ + size_t len = qemu_get_byte(f); + size_t res = qemu_get_buffer(f, (uint8_t *)buf, len); + + buf[res] = 0; + + return res == len ? res : 0; +} -- cgit v1.2.3