[PATCH 2/3] rpc: gendispatch: Add a check for zero size client-side buffers

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



After libvirt switched to GLib, we also started to use glib allocation
primitives as of commit e85e34f3. Unlike malloc which is ambiguous with
regards to size == 0 (which in our case returned a unique pointer safe
to be passed to free), g_malloc0 strictly returns NULL on size == 0.

This change broke our legacy APIs which rely on the caller to
pre-allocate the target buffer to hold the results and pass the buffer
size as an argument. Since it makes very little sense to call an API
with nowhere to store the results, fix this by returning 0 directly in
such case in the RPC dispatch code - there are modern API equivalents
allocating the target buffer automatically anyway.

https://bugzilla.redhat.com/show_bug.cgi?id=1772842

Signed-off-by: Erik Skultety <eskultet@xxxxxxxxxx>
---
 src/rpc/gendispatch.pl | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/src/rpc/gendispatch.pl b/src/rpc/gendispatch.pl
index 8656c8f205..524d31f741 100755
--- a/src/rpc/gendispatch.pl
+++ b/src/rpc/gendispatch.pl
@@ -1073,6 +1073,14 @@ elsif ($mode eq "server") {
             print "        goto cleanup;\n";
             print "    }\n";
             print "\n";
+
+
+            print "    if (args->$single_ret_list_max_var == 0) {\n";
+            print "        ret->$single_ret_list_name.${single_ret_list_name}_len = 0;\n";
+            print "        rv = 0;\n";
+            print "        goto cleanup;\n";
+            print "    }\n";
+            print "\n";
         }
 
         print join("\n", @getters_list);
-- 
2.23.0

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





[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux