[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH v6 04/47] Add qemu_get_counted_string to read a stri
From: |
Dr. David Alan Gilbert (git) |
Subject: |
[Qemu-devel] [PATCH v6 04/47] Add qemu_get_counted_string to read a string prefixed by a count byte |
Date: |
Tue, 14 Apr 2015 18:03:30 +0100 |
From: "Dr. David Alan Gilbert" <address@hidden>
and use it in loadvm_state and ram_load.
Signed-off-by: Dr. David Alan Gilbert <address@hidden>
---
arch_init.c | 5 +----
include/migration/qemu-file.h | 3 +++
migration/qemu-file.c | 16 ++++++++++++++++
savevm.c | 11 ++++++-----
4 files changed, 26 insertions(+), 9 deletions(-)
diff --git a/arch_init.c b/arch_init.c
index 4c8fcee..06722bb 100644
--- a/arch_init.c
+++ b/arch_init.c
@@ -1145,13 +1145,10 @@ static int ram_load(QEMUFile *f, void *opaque, int
version_id)
total_ram_bytes = addr;
while (!ret && total_ram_bytes) {
RAMBlock *block;
- uint8_t len;
char id[256];
ram_addr_t length;
- len = qemu_get_byte(f);
- qemu_get_buffer(f, (uint8_t *)id, len);
- id[len] = 0;
+ qemu_get_counted_string(f, id);
length = qemu_get_be64(f);
QLIST_FOREACH_RCU(block, &ram_list.blocks, next) {
diff --git a/include/migration/qemu-file.h b/include/migration/qemu-file.h
index 745a850..236a2e4 100644
--- a/include/migration/qemu-file.h
+++ b/include/migration/qemu-file.h
@@ -309,4 +309,7 @@ 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, char buf[256]);
+
#endif
diff --git a/migration/qemu-file.c b/migration/qemu-file.c
index 1a4f986..6c18e55 100644
--- a/migration/qemu-file.c
+++ b/migration/qemu-file.c
@@ -546,3 +546,19 @@ uint64_t qemu_get_be64(QEMUFile *f)
v |= qemu_get_be32(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, char buf[256])
+{
+ unsigned int len = qemu_get_byte(f);
+ int res = qemu_get_buffer(f, (uint8_t *)buf, len);
+
+ buf[len] = 0;
+
+ return res != len;
+}
+
diff --git a/savevm.c b/savevm.c
index c08abcc..9795e2e 100644
--- a/savevm.c
+++ b/savevm.c
@@ -969,8 +969,7 @@ 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];
trace_qemu_loadvm_state_section(section_type);
switch (section_type) {
@@ -978,9 +977,11 @@ int qemu_loadvm_state(QEMUFile *f)
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, 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);
--
2.1.0
- [Qemu-devel] [PATCH v6 00/47] Postcopy implementation, Dr. David Alan Gilbert (git), 2015/04/14
- [Qemu-devel] [PATCH v6 02/47] Split header writing out of qemu_savevm_state_begin, Dr. David Alan Gilbert (git), 2015/04/14
- [Qemu-devel] [PATCH v6 01/47] Start documenting how postcopy works., Dr. David Alan Gilbert (git), 2015/04/14
- [Qemu-devel] [PATCH v6 04/47] Add qemu_get_counted_string to read a string prefixed by a count byte,
Dr. David Alan Gilbert (git) <=
- [Qemu-devel] [PATCH v6 03/47] qemu_ram_foreach_block: pass up error value, and down the ramblock name, Dr. David Alan Gilbert (git), 2015/04/14
- [Qemu-devel] [PATCH v6 05/47] Create MigrationIncomingState, Dr. David Alan Gilbert (git), 2015/04/14
- [Qemu-devel] [PATCH v6 06/47] Provide runtime Target page information, Dr. David Alan Gilbert (git), 2015/04/14
- [Qemu-devel] [PATCH v6 09/47] Add wrapper for setting blocking status on a QEMUFile, Dr. David Alan Gilbert (git), 2015/04/14
- [Qemu-devel] [PATCH v6 07/47] Move copy out of qemu_peek_buffer, Dr. David Alan Gilbert (git), 2015/04/14
- [Qemu-devel] [PATCH v6 13/47] Migration commands, Dr. David Alan Gilbert (git), 2015/04/14
- [Qemu-devel] [PATCH v6 10/47] Rename save_live_complete to save_live_complete_precopy, Dr. David Alan Gilbert (git), 2015/04/14
- [Qemu-devel] [PATCH v6 12/47] Return path: socket_writev_buffer: Block even on non-blocking fd's, Dr. David Alan Gilbert (git), 2015/04/14
- [Qemu-devel] [PATCH v6 08/47] Add qemu_get_buffer_less_copy to avoid copies some of the time, Dr. David Alan Gilbert (git), 2015/04/14
- [Qemu-devel] [PATCH v6 11/47] Return path: Open a return path on QEMUFile for sockets, Dr. David Alan Gilbert (git), 2015/04/14