Re: [libvirt] [PATCH] util.c (virGetUserEnt): don't use a negative value as allocation size

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

 



2010/1/28 Jim Meyering <jim@xxxxxxxxxxxx>:
> Not a big deal, but reporting a failed sysconf call will make
> this far easier to diagnose than reporting an unwarranted OOM.
>
> >From 2bf48c9414cac791f03228ff15590414ec617f22 Mon Sep 17 00:00:00 2001
> From: Jim Meyering <meyering@xxxxxxxxxx>
> Date: Thu, 28 Jan 2010 13:37:05 +0100
> Subject: [PATCH] util.c (virGetUserEnt): don't use a negative value as allocation size
>
> * src/util/util.c (virGetUserEnt): In the unlikely event that
> sysconf(_SC_GETPW_R_SIZE_MAX) fails, don't use -1 as the size in
> the subsequent allocation.
> ---
>  src/util/util.c |    8 +++++++-
>  1 files changed, 7 insertions(+), 1 deletions(-)
>
> diff --git a/src/util/util.c b/src/util/util.c
> index 0ce5026..701581d 100644
> --- a/src/util/util.c
> +++ b/src/util/util.c
> @@ -2317,7 +2317,13 @@ static char *virGetUserEnt(virConnectPtr conn,
>     char *ret;
>     struct passwd pwbuf;
>     struct passwd *pw = NULL;
> -    size_t strbuflen = sysconf(_SC_GETPW_R_SIZE_MAX);
> +    long val = sysconf(_SC_GETPW_R_SIZE_MAX);
> +    size_t strbuflen = val;
> +
> +    if (val < 0) {
> +        virReportSystemError(conn, errno, "%s", _("sysconf failed"));
> +        return NULL;
> +    }
>
>     if (VIR_ALLOC_N(strbuf, strbuflen) < 0) {
>         virReportOOMError(conn);
> --
> 1.7.0.rc0.170.g7207c
>

ACK.

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]