git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH v3 1/2] use HOST_NAME_MAX to size buffers for gethostname(2)

From
Torsten Bögershausen <tboegi@web.de>
Date
Apr 20, 2017, 18:37 UTC
Message-ID
<a718ca38-4c07-9f3d-e7f5-9efd7ef59007@web.de>
In-Reply-To
<7d075a07-edc9-83eb-25cf-7f8b13700584@web.de>
On 2017-04-19 22:02, René Scharfe wrote:
Show 48 quoted lines
> Am 19.04.2017 um 21:09 schrieb Torsten Bögershausen:
>> On 2017-04-19 19:28, René Scharfe wrote:
>> []
>> One or two minor comments inline
>>> diff --git a/builtin/gc.c b/builtin/gc.c
>>> index 2daede7820..4c1c01e87d 100644
>>> --- a/builtin/gc.c
>>> +++ b/builtin/gc.c
>>> @@ -228,21 +228,99 @@ static int need_to_gc(void)
>>>       return 1;
>>>   }
>>>   +struct pidfile {
>>> +    struct strbuf buf;
>>> +    char *hostname;
>>> +};
>>> +
>>> +#define PIDFILE_INIT { STRBUF_INIT }
>>> +
>>> +static void pidfile_release(struct pidfile *pf)
>>> +{
>>> +    pf->hostname = NULL;
>>> +    strbuf_release(&pf->buf);
>>> +}
>>> +
>>> +static int pidfile_read(struct pidfile *pf, const char *path,
>>> +            unsigned int max_age_seconds)
>>> +{
>>> +    int fd;
>>> +    struct stat st;
>>> +    ssize_t len;
>>> +    char *space;
>>> +    int rc = -1;
>>> +
>>> +    fd = open(path, O_RDONLY);
>>> +    if (fd < 0)
>>> +        return rc;
>>> +
>>> +    if (fstat(fd, &st))
>>> +        goto out;
>>> +    if (time(NULL) - st.st_mtime > max_age_seconds)
>>> +        goto out;
>>> +    if (st.st_size > (size_t)st.st_size)
>>
>> Minor: we need xsize_t here ?
>> if (st.st_size > xsize_t(st.st_size))
> 
> No, xsize_t() would do the same check and die on overflow, and pidfile_read() is
> supposed to handle big pids gracefully.

This about the file size, isn't it ? And here xsize_t should be save to use and good practise.

Previous: René ScharfeNext: René Scharfe
Message 16 of 18 in “gethostbyname fixes”
  1. 0/2 gethostbyname fixesDavid Turner, Apr 18, 2017
  2. 2/2 xgethostname: handle long hostnamesDavid Turner, Apr 18, 2017
  3. Jonathan NiederApr 19, 2017
  4. Junio C HamanoApr 19, 2017
  5. David TurnerApr 19, 2017
  6. René ScharfeApr 19, 2017
  7. Junio C HamanoApr 19, 2017
  8. 1/2 use HOST_NAME_MAX to size buffers for gethostname(2)David Turner, Apr 18, 2017
  9. Jonathan NiederApr 19, 2017
  10. Junio C HamanoApr 19, 2017
  11. René ScharfeApr 19, 2017
  12. René ScharfeApr 19, 2017
  13. David TurnerApr 19, 2017
  14. Torsten BögershausenApr 19, 2017
  15. René ScharfeApr 19, 2017
  16. Torsten BögershausenApr 20, 2017
  17. René ScharfeApr 20, 2017
  18. Torsten BögershausenApr 21, 2017

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.