Re: [PATCH] util: Fix leak in virStringTrimOptionalNewline

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

 



On 11/22/2017 10:03 PM, Martin Kletzander wrote:
> Do not access any data if strlen() == 0.
> 
> Signed-off-by: Martin Kletzander <mkletzan@xxxxxxxxxx>
> ---
>  src/util/virstring.c | 10 +++++++---
>  1 file changed, 7 insertions(+), 3 deletions(-)
> 
> diff --git a/src/util/virstring.c b/src/util/virstring.c
> index eac4774b533e..b2ebce27ff49 100644
> --- a/src/util/virstring.c
> +++ b/src/util/virstring.c
> @@ -1394,9 +1394,13 @@ virStringEncodeBase64(const uint8_t *buf, size_t buflen)
>   */
>  void virStringTrimOptionalNewline(char *str)
>  {
> -    char *tmp = str + strlen(str) - 1;
> -    if (*tmp == '\n')
> -        *tmp = '\0';
> +    size_t len = strlen(str);
> +
> +    if (!len)
> +        return;
> +
> +    if (str[len - 1] == '\n')
> +        str[len - 1] = '\0';
>  }
>  
>  
> 

/me wonders if we need this function to accept NULL. Looking at the
callers we don't just yet.

ACK

Michal

--
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]
  Powered by Linux