bug-hurd
[Top][All Lists]
Advanced

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

Re: [PATCH] ftpfs: fix host lookup error handling


From: Samuel Thibault
Subject: Re: [PATCH] ftpfs: fix host lookup error handling
Date: Mon, 26 Aug 2019 20:36:34 +0200
User-agent: NeoMutt/20170609 (1.8.3)

Hello,

Krzysztof Piecuch, le lun. 26 août 2019 17:54:55 +0000, a ecrit:
> -  if (gethostbyname_r (host, &_he, hostent_data, sizeof hostent_data,
> -                    &he, h_err) == 0)
> +  do {
> +    bufsize *= 2;
> +    hostent_data = realloc(hostent_data, bufsize);
> +    if (!hostent_data)
> +      err = ENOMEM;

When realloc fails, the previous buffer is not released, so you mustn't
immediately overwrite hostent_data with the new pointer, but use an
intermediate temporary variable.

> +    retval = gethostbyname_r (host, &_he, hostent_data, bufsize,
> +                              &he, h_err);
> +  }  while (!err && retval == ERANGE && bufsize < bufsizemax);

The GNU Coding Style prefers to use err == 0. Also replace the two
spaces with just one space.

>    else
>      err = EINVAL;

This will overwrite the ENOMEM mentioned above.

In the commit log, please not only mention why the commit, but also what
it contains, see previous log entries for instance. Here you could have

* ftpfs/host.c (lookup_server): Fix coding style. On ENOMEM of realloc,
return ENOMEM instead of overwriting it with EINVAL.

Samuel



reply via email to

[Prev in Thread] Current Thread [Next in Thread]