[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH v4 06/47] Add qemu_get_counted_string to read a stri
From: |
Dr. David Alan Gilbert (git) |
Subject: |
[Qemu-devel] [PATCH v4 06/47] Add qemu_get_counted_string to read a string prefixed by a count byte |
Date: |
Fri, 3 Oct 2014 18:47:12 +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 6ef8ebc..a8cac7a 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 ccc516c..a057b3e 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 (16 * 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 v4 00/47] Postcopy implementation, Dr. David Alan Gilbert (git), 2014/10/03
- [Qemu-devel] [PATCH v4 01/47] QEMUSizedBuffer based QEMUFile, Dr. David Alan Gilbert (git), 2014/10/03
- [Qemu-devel] [PATCH v4 02/47] Tests: QEMUSizedBuffer/QEMUBuffer, Dr. David Alan Gilbert (git), 2014/10/03
- [Qemu-devel] [PATCH v4 03/47] Start documenting how postcopy works., Dr. David Alan Gilbert (git), 2014/10/03
- [Qemu-devel] [PATCH v4 05/47] improve DPRINTF macros, add to savevm, Dr. David Alan Gilbert (git), 2014/10/03
- [Qemu-devel] [PATCH v4 04/47] qemu_ram_foreach_block: pass up error value, and down the ramblock name, Dr. David Alan Gilbert (git), 2014/10/03
- [Qemu-devel] [PATCH v4 06/47] Add qemu_get_counted_string to read a string prefixed by a count byte,
Dr. David Alan Gilbert (git) <=
- [Qemu-devel] [PATCH v4 07/47] Create MigrationIncomingState, Dr. David Alan Gilbert (git), 2014/10/03
- [Qemu-devel] [PATCH v4 08/47] socket shutdown, Dr. David Alan Gilbert (git), 2014/10/03
- [Qemu-devel] [PATCH v4 09/47] Provide runtime Target page information, Dr. David Alan Gilbert (git), 2014/10/03
- [Qemu-devel] [PATCH v4 10/47] Return path: Open a return path on QEMUFile for sockets, Dr. David Alan Gilbert (git), 2014/10/03
- [Qemu-devel] [PATCH v4 12/47] Handle bi-directional communication for fd migration, Dr. David Alan Gilbert (git), 2014/10/03
- [Qemu-devel] [PATCH v4 11/47] Return path: socket_writev_buffer: Block even on non-blocking fd's, Dr. David Alan Gilbert (git), 2014/10/03
- [Qemu-devel] [PATCH v4 13/47] Migration commands, Dr. David Alan Gilbert (git), 2014/10/03