[libvirt] [PATCH] qemu_monitor: s/size_t/ULL/ in qemuMonitorSave{Virtual, Physical}Memory

Michal Privoznik posted 1 patch 4 years, 7 months ago
Test syntax-check passed
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/libvirt tags/patchew/5a1f83b9ddfa9f0099bf5ab1955556cd561ce07b.1569585446.git.mprivozn@redhat.com
src/qemu/qemu_monitor.c      | 8 ++++----
src/qemu/qemu_monitor.h      | 4 ++--
src/qemu/qemu_monitor_json.c | 6 +++---
src/qemu/qemu_monitor_json.h | 4 ++--
4 files changed, 11 insertions(+), 11 deletions(-)
[libvirt] [PATCH] qemu_monitor: s/size_t/ULL/ in qemuMonitorSave{Virtual, Physical}Memory
Posted by Michal Privoznik 4 years, 7 months ago
As it turns out, on my 32bit ARM machine size_t is not the same
size as ULL. However, @length argument for both functions is type
of size_t but it's treated as ULL - for instance when passed to
qemuMonitorJSONMakeCommand(). The problem is that because of
"U:size" the virJSONValueObjectAddVArgs() expects an ULL argument
but on the stack there are size_t and char * arguments (which
coincidentally add up to size of ULL). So the created command has
only two arguments "val" and incorrect "size" and no "path" which
is required.

I've tried to find other occurrences of this pattern but at the
rest of places where size_t is used it tracks size of an array so
that's safe.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
---
 src/qemu/qemu_monitor.c      | 8 ++++----
 src/qemu/qemu_monitor.h      | 4 ++--
 src/qemu/qemu_monitor_json.c | 6 +++---
 src/qemu/qemu_monitor_json.h | 4 ++--
 4 files changed, 11 insertions(+), 11 deletions(-)

diff --git a/src/qemu/qemu_monitor.c b/src/qemu/qemu_monitor.c
index b6d2936872..7959933e7c 100644
--- a/src/qemu/qemu_monitor.c
+++ b/src/qemu/qemu_monitor.c
@@ -2348,10 +2348,10 @@ qemuMonitorChangeMedia(qemuMonitorPtr mon,
 int
 qemuMonitorSaveVirtualMemory(qemuMonitorPtr mon,
                              unsigned long long offset,
-                             size_t length,
+                             unsigned long long length,
                              const char *path)
 {
-    VIR_DEBUG("offset=%llu length=%zu path=%s", offset, length, path);
+    VIR_DEBUG("offset=%llu length=%llu path=%s", offset, length, path);
 
     QEMU_CHECK_MONITOR(mon);
 
@@ -2362,10 +2362,10 @@ qemuMonitorSaveVirtualMemory(qemuMonitorPtr mon,
 int
 qemuMonitorSavePhysicalMemory(qemuMonitorPtr mon,
                               unsigned long long offset,
-                              size_t length,
+                              unsigned long long length,
                               const char *path)
 {
-    VIR_DEBUG("offset=%llu length=%zu path=%s", offset, length, path);
+    VIR_DEBUG("offset=%llu length=%llu path=%s", offset, length, path);
 
     QEMU_CHECK_MONITOR(mon);
 
diff --git a/src/qemu/qemu_monitor.h b/src/qemu/qemu_monitor.h
index 8fc11c955e..95de891150 100644
--- a/src/qemu/qemu_monitor.h
+++ b/src/qemu/qemu_monitor.h
@@ -726,11 +726,11 @@ int qemuMonitorChangeMedia(qemuMonitorPtr mon,
 
 int qemuMonitorSaveVirtualMemory(qemuMonitorPtr mon,
                                  unsigned long long offset,
-                                 size_t length,
+                                 unsigned long long length,
                                  const char *path);
 int qemuMonitorSavePhysicalMemory(qemuMonitorPtr mon,
                                   unsigned long long offset,
-                                  size_t length,
+                                  unsigned long long length,
                                   const char *path);
 
 int qemuMonitorSetMigrationSpeed(qemuMonitorPtr mon,
diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c
index cdfaf9785a..d99d291d89 100644
--- a/src/qemu/qemu_monitor_json.c
+++ b/src/qemu/qemu_monitor_json.c
@@ -3100,7 +3100,7 @@ int qemuMonitorJSONChangeMedia(qemuMonitorPtr mon,
 static int qemuMonitorJSONSaveMemory(qemuMonitorPtr mon,
                                      const char *cmdtype,
                                      unsigned long long offset,
-                                     size_t length,
+                                     unsigned long long length,
                                      const char *path)
 {
     int ret = -1;
@@ -3129,7 +3129,7 @@ static int qemuMonitorJSONSaveMemory(qemuMonitorPtr mon,
 
 int qemuMonitorJSONSaveVirtualMemory(qemuMonitorPtr mon,
                                      unsigned long long offset,
-                                     size_t length,
+                                     unsigned long long length,
                                      const char *path)
 {
     return qemuMonitorJSONSaveMemory(mon, "memsave", offset, length, path);
@@ -3137,7 +3137,7 @@ int qemuMonitorJSONSaveVirtualMemory(qemuMonitorPtr mon,
 
 int qemuMonitorJSONSavePhysicalMemory(qemuMonitorPtr mon,
                                       unsigned long long offset,
-                                      size_t length,
+                                      unsigned long long length,
                                       const char *path)
 {
     return qemuMonitorJSONSaveMemory(mon, "pmemsave", offset, length, path);
diff --git a/src/qemu/qemu_monitor_json.h b/src/qemu/qemu_monitor_json.h
index a608410703..63f569716d 100644
--- a/src/qemu/qemu_monitor_json.h
+++ b/src/qemu/qemu_monitor_json.h
@@ -118,11 +118,11 @@ int qemuMonitorJSONChangeMedia(qemuMonitorPtr mon,
 
 int qemuMonitorJSONSaveVirtualMemory(qemuMonitorPtr mon,
                                      unsigned long long offset,
-                                     size_t length,
+                                     unsigned long long length,
                                      const char *path);
 int qemuMonitorJSONSavePhysicalMemory(qemuMonitorPtr mon,
                                       unsigned long long offset,
-                                      size_t length,
+                                      unsigned long long length,
                                       const char *path);
 
 int qemuMonitorJSONSetMigrationSpeed(qemuMonitorPtr mon,
-- 
2.21.0

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH] qemu_monitor: s/size_t/ULL/ in qemuMonitorSave{Virtual, Physical}Memory
Posted by Peter Krempa 4 years, 7 months ago
On Fri, Sep 27, 2019 at 13:57:26 +0200, Michal Privoznik wrote:
> As it turns out, on my 32bit ARM machine size_t is not the same
> size as ULL. However, @length argument for both functions is type
> of size_t but it's treated as ULL - for instance when passed to
> qemuMonitorJSONMakeCommand(). The problem is that because of
> "U:size" the virJSONValueObjectAddVArgs() expects an ULL argument
> but on the stack there are size_t and char * arguments (which
> coincidentally add up to size of ULL). So the created command has
> only two arguments "val" and incorrect "size" and no "path" which
> is required.
> 
> I've tried to find other occurrences of this pattern but at the
> rest of places where size_t is used it tracks size of an array so
> that's safe.
> 
> Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
> ---
>  src/qemu/qemu_monitor.c      | 8 ++++----
>  src/qemu/qemu_monitor.h      | 4 ++--
>  src/qemu/qemu_monitor_json.c | 6 +++---
>  src/qemu/qemu_monitor_json.h | 4 ++--
>  4 files changed, 11 insertions(+), 11 deletions(-)

ACK

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list