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

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

 



Eric Blake <eblake@xxxxxxxxxx> wrote on 03/10/2014 02:09:58 PM:

> From: Eric Blake <eblake@xxxxxxxxxx>

> To: Stefan Berger/Watson/IBM@IBMUS, libvir-list@xxxxxxxxxx,
> Cc: laine@xxxxxxxxx
> Date: 03/10/2014 02:24 PM
> Subject: Re: [PATCH] BZ1072677: Avoid freeing of 0 file descriptor
>
> 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'?


It's probably too general for the fd purpose here only.

>
> > +
> > +/* 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().


Also this would be possible.

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


So a simple memset() would do? Having a macro for VIR_ALLOC_N_FD() would probably be too much, eh?

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