Skip to contentSkip to conversation

migration: fix bad string passed to error_report()

PATCH Superseded Greg Kurz 3 participants 4 messages Feb 4, 2016

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Greg Kurz

author
#0 lore raw

PATCH 1/1 migration: fix bad string passed to error_report()

state->name does not contain a terminating '\0' and you may get:

Machine type received is 'pseries-2.3y�?' and local is 'pseries-2.4' load of migration failed: Invalid argument

Let's add a precision modifier to fix this.

---
 migration/savevm.c |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
migration/savevm.c +2 -2
index 954988d12130..3335cc23175c 100644
@@ -299,8 +299,8 @@ static int configuration_post_load(void *opaque, int version_id)
     const char *current_name = MACHINE_GET_CLASS(current_machine)->name;
 
     if (strncmp(state->name, current_name, state->len) != 0) {
-        error_report("Machine type received is '%s' and local is '%s'",
-                     state->name, current_name);
+        error_report("Machine type received is '%.*s' and local is '%s'",
+                     state->len, state->name, current_name);
         return -EINVAL;
     }
     return 0;
Reviewed-by on v1 1/1
#1 lore raw
Quoted 8 lines · Greg Kurz

state->name does not contain a terminating '\0' and you may get:

Machine type received is 'pseries-2.3y�?' and local is 'pseries-2.4' load of migration failed: Invalid argument

Let's add a precision modifier to fix this.

Amit

author
#2 lore raw
Quoted 6 lines · On Thu, 4 Feb 2016 15:30:11 +0530 Amit Shah <[email protected]> wrote:
Quoted 5 lines · Greg Kurz

state->name does not contain a terminating '\0' and you may get:

Machine type received is 'pseries-2.3y�?' and local is 'pseries-2.4' load of migration failed: Invalid argument

Quoted 8 lines
Quoted 3 lines

Let's add a precision modifier to fix this.

Amit

I forgot to mention that this patch fixes:

61964c23e5ddd5a33f15699e45ce126f879e3e33 "migration: Add configuration section"

Cc'ing stable since this is a 2.4.0 commit and it may *theorically* lead to a crash (even if that is very unlikely to occur).

Also Cc'ing trivial.

Thanks !

--
Greg

#3 lore raw
In reply to Greg Kurz
Quoted 17 lines · Greg Kurz

state->name does not contain a terminating '\0' and you may get:

Machine type received is 'pseries-2.3y�?' and local is 'pseries-2.4' load of migration failed: Invalid argument

Let's add a precision modifier to fix this.

---
 migration/savevm.c |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
migration/savevm.c +0 -0
index 954988d12130..3335cc23175c 100644

migration/savevm.c static int configuration_post_load(void *opaque, int version_id) · line 303

Quoted 7 lines
migration/savevm.c +2 -2
@@ -299,8 +299,8 @@ static int configuration_post_load(void *opaque, int version_id)
     const char *current_name = MACHINE_GET_CLASS(current_machine)->name;
 
     if (strncmp(state->name, current_name, state->len) != 0) {
-        error_report("Machine type received is '%s' and local is '%s'",
-                     state->name, current_name);
+        error_report("Machine type received is '%.*s' and local is '%s'",
+                     state->len, state->name, current_name);

.* required an 'int', but SaveState.len is uint32_t. There are platforms (hello, 32-bit cygwin) where uint32_t is a long, and where this would therefore cause a compiler warning. You'll be safer with an explicit cast, '(int) state->len'.

Signature · 2 lines
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org