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

Guillem Jover
2011-09-25T04:05:35Z

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,
guillem