[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH v3 06/47] Add qemu_get_counted_string to read a stri
From: |
Dr. David Alan Gilbert (git) |
Subject: |
[Qemu-devel] [PATCH v3 06/47] Add qemu_get_counted_string to read a string prefixed by a count byte |
Date: |
Thu, 28 Aug 2014 16:03:23 +0100 |
From: "Dr. David Alan Gilbert" <address@hidden>
and use it in loadvm_state.
Signed-off-by: Dr. David Alan Gilbert <address@hidden>
---
include/migration/qemu-file.h | 2 ++
qemu-file.c | 15 +++++++++++++++
savevm.c | 18 ++++++++++--------
3 files changed, 27 insertions(+), 8 deletions(-)
diff --git a/include/migration/qemu-file.h b/include/migration/qemu-file.h
index 80af3ff..e50d696 100644
--- a/include/migration/qemu-file.h
+++ b/include/migration/qemu-file.h
@@ -300,4 +300,6 @@ static inline void qemu_get_sbe64s(QEMUFile *f, int64_t *pv)
{
qemu_get_be64s(f, (uint64_t *)pv);
}
+
+int qemu_get_counted_string(QEMUFile *f, uint8_t *buf);
#endif
diff --git a/qemu-file.c b/qemu-file.c
index d64bee2..f6d64ce 100644
--- a/qemu-file.c
+++ b/qemu-file.c
@@ -879,6 +879,21 @@ uint64_t qemu_get_be64(QEMUFile *f)
return v;
}
+/*
+ * Get a string whose length is determined by a single preceding byte
+ * A preallocated 256 byte buffer must be passed in.
+ * Returns: 0 on success and a 0 terminated string in the buffer
+ */
+int qemu_get_counted_string(QEMUFile *f, uint8_t *buf)
+{
+ unsigned int len = qemu_get_byte(f);
+ int res = qemu_get_buffer(f, buf, len);
+
+ buf[len] = 0;
+
+ return res != len;
+}
+
#define QSB_CHUNK_SIZE (1 << 10)
#define QSB_MAX_CHUNK_SIZE (10 * QSB_CHUNK_SIZE)
diff --git a/savevm.c b/savevm.c
index c3a1f68..cb6f0de 100644
--- a/savevm.c
+++ b/savevm.c
@@ -908,7 +908,7 @@ int qemu_loadvm_state(QEMUFile *f)
v = qemu_get_be32(f);
if (v == QEMU_VM_FILE_VERSION_COMPAT) {
- fprintf(stderr, "SaveVM v2 format is obsolete and don't work
anymore\n");
+ error_report("SaveVM v2 format is obsolete and don't work anymore");
return -ENOTSUP;
}
if (v != QEMU_VM_FILE_VERSION) {
@@ -918,31 +918,33 @@ int qemu_loadvm_state(QEMUFile *f)
while ((section_type = qemu_get_byte(f)) != QEMU_VM_EOF) {
uint32_t instance_id, version_id, section_id;
SaveStateEntry *se;
- char idstr[257];
- int len;
+ char idstr[256];
switch (section_type) {
case QEMU_VM_SECTION_START:
case QEMU_VM_SECTION_FULL:
/* Read section start */
section_id = qemu_get_be32(f);
- len = qemu_get_byte(f);
- qemu_get_buffer(f, (uint8_t *)idstr, len);
- idstr[len] = 0;
+ if (qemu_get_counted_string(f, (uint8_t *)idstr)) {
+ error_report("Unable to read ID string for section %u",
+ section_id);
+ return -EINVAL;
+ }
instance_id = qemu_get_be32(f);
version_id = qemu_get_be32(f);
/* Find savevm section */
se = find_se(idstr, instance_id);
if (se == NULL) {
- fprintf(stderr, "Unknown savevm section or instance '%s'
%d\n", idstr, instance_id);
+ error_report("Unknown savevm section or instance '%s' %d",
+ idstr, instance_id);
ret = -EINVAL;
goto out;
}
/* Validate version */
if (version_id > se->version_id) {
- fprintf(stderr, "savevm: unsupported version %d for '%s'
v%d\n",
+ error_report("savevm: unsupported version %d for '%s' v%d",
version_id, idstr, se->version_id);
ret = -EINVAL;
goto out;
--
1.9.3
- [Qemu-devel] [PATCH v3 02/47] Tests: QEMUSizedBuffer/QEMUBuffer, (continued)
- [Qemu-devel] [PATCH v3 02/47] Tests: QEMUSizedBuffer/QEMUBuffer, Dr. David Alan Gilbert (git), 2014/08/28
- [Qemu-devel] [PATCH v3 05/47] improve DPRINTF macros, add to savevm, Dr. David Alan Gilbert (git), 2014/08/28
- [Qemu-devel] [PATCH v3 08/47] socket shutdown, Dr. David Alan Gilbert (git), 2014/08/28
- [Qemu-devel] [PATCH v3 10/47] Return path: socket_writev_buffer: Block even on non-blocking fd's, Dr. David Alan Gilbert (git), 2014/08/28
- [Qemu-devel] [PATCH v3 14/47] Return path: Source handling of return path, Dr. David Alan Gilbert (git), 2014/08/28
- [Qemu-devel] [PATCH v3 09/47] Return path: Open a return path on QEMUFile for sockets, Dr. David Alan Gilbert (git), 2014/08/28
- [Qemu-devel] [PATCH v3 12/47] Return path: Control commands, Dr. David Alan Gilbert (git), 2014/08/28
- [Qemu-devel] [PATCH v3 13/47] Return path: Send responses from destination to source, Dr. David Alan Gilbert (git), 2014/08/28
- [Qemu-devel] [PATCH v3 16/47] ram_debug_dump_bitmap: Dump a migration bitmap as text, Dr. David Alan Gilbert (git), 2014/08/28
- [Qemu-devel] [PATCH v3 17/47] Rework loadvm path for subloops, Dr. David Alan Gilbert (git), 2014/08/28
- [Qemu-devel] [PATCH v3 06/47] Add qemu_get_counted_string to read a string prefixed by a count byte,
Dr. David Alan Gilbert (git) <=
- [Qemu-devel] [PATCH v3 18/47] Add migration-capability boolean for postcopy-ram., Dr. David Alan Gilbert (git), 2014/08/28
- [Qemu-devel] [PATCH v3 20/47] QEMU_VM_CMD_PACKAGED: Send a packaged chunk of migration stream, Dr. David Alan Gilbert (git), 2014/08/28
- [Qemu-devel] [PATCH v3 22/47] Allow savevm handlers to state whether they could go into postcopy, Dr. David Alan Gilbert (git), 2014/08/28
- [Qemu-devel] [PATCH v3 23/47] postcopy: OS support test, Dr. David Alan Gilbert (git), 2014/08/28
- [Qemu-devel] [PATCH v3 11/47] Migration commands, Dr. David Alan Gilbert (git), 2014/08/28
- [Qemu-devel] [PATCH v3 21/47] migrate_init: Call from savevm, Dr. David Alan Gilbert (git), 2014/08/28
- [Qemu-devel] [PATCH v3 24/47] migrate_start_postcopy: Command to trigger transition to postcopy, Dr. David Alan Gilbert (git), 2014/08/28
- [Qemu-devel] [PATCH v3 25/47] MIG_STATE_POSTCOPY_ACTIVE: Add new migration state, Dr. David Alan Gilbert (git), 2014/08/28
- [Qemu-devel] [PATCH v3 27/47] Postcopy: Maintain sentmap during postcopy pre phase, Dr. David Alan Gilbert (git), 2014/08/28
- [Qemu-devel] [PATCH v3 28/47] Postcopy page-map-incoming (PMI) structure, Dr. David Alan Gilbert (git), 2014/08/28