Re: [PATCH 7/7] openvz: use virAsprintf to avoid large stacks

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

 



2010/9/1 Eric Blake <eblake@xxxxxxxxxx>:
> * src/openvz/openvz_conf.c (openvzLocateConfFile): Alter
> signature.
> (openvzGetVPSUUID, openvzSetDefinedUUID)
> (openvzWriteVPSConfigParam, openvzReadVPSConfigParam)
> (openvzCopyDefaultConfig): Adjust callers.
> ---
>
> Nuke a few more PATH_MAX stack allocations.
>
>  src/openvz/openvz_conf.c |   78 ++++++++++++++++++++++++++++-----------------
>  1 files changed, 48 insertions(+), 30 deletions(-)
>

> @@ -861,12 +869,18 @@ openvzGetVPSUUID(int vpsid, char *uuidstr, size_t len)
>         uuidbuf = strtok_r(NULL, "\n", &saveptr);
>
>         if (iden != NULL && uuidbuf != NULL && STREQ(iden, "#UUID:")) {
> -            if (virStrcpy(uuidstr, uuidbuf, len) == NULL)
> -                retval = -1;
> +            if (virStrcpy(uuidstr, uuidbuf, len) == NULL) {
> +                virReportOOMError();
> +                goto cleanup;
> +            }

virStrcpy cannot fail because of OOM, it doesn't do an allocation.
When it returns NULL, this means that one tried to copy too much data
to the given destination buffer. The typical error message in such a
case looks like this:

    if (virStrcpy(sa_qemu.sun_path, unixfile,
                  sizeof(sa_qemu.sun_path)) == NULL) {
        qemuReportError(VIR_ERR_INTERNAL_ERROR,
                        _("Unix socket '%s' too big for destination"),
                        unixfile);
        goto cleanup;
    }

>             break;
>         }
>     }
> -    close(fd);
> +    retval = 0;
> +cleanup:
> +    if (0 <= fd)

if (fd >= 0) reads nicer here.

> +        close(fd);
> +    VIR_FREE(conf_file);
>
>     return retval;
>  }

ACK, with these two comments addressed.

Matthias

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