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

Re: [libvirt] [PATCH 3/7] vbox: avoid problematic uses of sprintf



On 09/02/2010 05:43 AM, Matthias Bolte wrote:
-                        /* Assuming can't have more then 9999 devices so
-                         * restricting to %04d
+                        /* Zero pad for nice alignment when fewer than 9999
+                         * devices.
                          */
-                        sprintf(filtername, "filter%04d", i);
-                        VBOX_UTF8_TO_UTF16(filtername,&filternameUtf16);
+                        if (virAsprintf(&filtername, "filter%04d", i)<  0) {
+                            virReportOOMError();
+                        } else {
+                            VBOX_UTF8_TO_UTF16(filtername,&filternameUtf16);
+                            VIR_FREE(filtername);
+                        }

                         USBController->vtbl->CreateDeviceFilter(USBController,
                                                                 filternameUtf16,

In case virAsprintf fails CreateDeviceFilter will be called with
filternameUtf16 = NULL, that might trigger a segfault.

Good catch. I'll respin this patch as part of my round 3 cleanups (more openvz_driver changes, and virsh.c, still to come). It may be another day or two...

--
Eric Blake   eblake redhat com    +1-801-349-2682
Libvirt virtualization library http://libvirt.org


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