Re: [PATCH] readlink.2: Document using st_size to allocate the buffer

Michael Kerrisk
2011-09-25T04:55:38Z

Hi Guillem

On Sun, Sep 25, 2011 at 6:05 AM, Guillem Jover <guillem-+FW4gsLVM0RAfugRpC6u6w@public.gmane.org> wrote:
> Hi!
>
> On Tue, 2011-09-20 at 08:51:41 +0200, Michael Kerrisk wrote:
>> I made some edits to your patch, and placed the added explanatory text
>> in NOTES, rather than DESCRIPTION. Modified patch below.
>>
>> The change will be in 3.34.
>
> Thanks! Looks good.
>
>> diff --git a/man2/readlink.2 b/man2/readlink.2
>> index c9f6d92..051a870 100644
>> --- a/man2/readlink.2
>> +++ b/man2/readlink.2
>> @@ -1,4 +1,5 @@
>>  .\" Copyright (c) 1983, 1991 The Regents of the University of California.
>> +.\" Adn Copyright (C) 2011 Guillem Jover <guillem-+FW4gsLVM0RAfugRpC6u6w@public.gmane.org>
>
> Small typo: Adn → And.
>
>> +    r = readlink(argv[1], linkname, sb.st_size + 1);
>> +
>> +    if (r < 0) {
>> +        perror("lstat");
>> +        exit(EXIT_FAILURE);
>> +    }
>> +
>> +    if (r != sb.st_size) {
>> +        fprintf(stderr, "symlink increased in size "
>> +                        "between lstat() and readlink()\\n");
>> +        exit(EXIT_FAILURE);
>> +    }
>
> You might want to change the check condition to “r > sb.st_size” to
> match the new error string.

Thanks for checking that. Fixed now in git.

Cheers,

Michael
--
Michael Kerrisk
Linux man-pages maintainer; http://www.kernel.org/doc/man-pages/
Author of "The Linux Programming Interface"; http://man7.org/tlpi/