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

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



2010/9/1 Eric Blake <eblake redhat com>:
> * 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


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