Re: [PATCH] BZ1072677: Avoid freeing of 0 file descriptor

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

 



On 03/08/2014 04:29 PM, Stefan Berger wrote:
> From: Stefan Berger <stefanb@xxxxxxxxxxxxxxxxxx>
> 
> Avoid the freeing of an array of zero file descriptors in case
> of error. Introduce a macro VIR_INIT_N_FD to initialize such
> an array's elements to -1.
> 
> Signed-off-by: Stefan Berger <stefanb@xxxxxxxxxxxxxxxxxx>
> ---
>  src/qemu/qemu_hotplug.c | 14 +++++++++++---
>  src/util/virfile.h      | 12 ++++++++++++
>  2 files changed, 23 insertions(+), 3 deletions(-)
> 

> +++ b/src/util/virfile.h
> @@ -75,6 +75,18 @@ FILE *virFileFdopen(int *fdptr, const char *mode) ATTRIBUTE_RETURN_CHECK;
>                   VIR_FILE_CLOSE_PRESERVE_ERRNO |    \
>                   VIR_FILE_CLOSE_DONT_LOG))
>  
> +static inline void vir_init_n_int(int *ptr, int count, int value)
> +{
> +    int i;
> +
> +    for (i = 0; i < count; i++)
> +        ptr[i] = value;
> +}

Do we ever plan on using this for values other than '-1'?

> +
> +/* Initialize an array of file descriptors to -1 */
> +# define VIR_INIT_N_FD(ptr, count) \
> +    vir_init_n_int(ptr, count, -1)

Could also be spelled:

memset(ptr, -1, sizeof(*ptr) * count))

which goes back to why we need vir_init_n_int().

I agree that the fix to qemu_hotplug.c to not close fd 0 on failure is
needed, but am not sure about the complexity of the virfile.h addition.


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

Attachment: signature.asc
Description: OpenPGP digital signature

--
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]