Fix possible race condition in readlink.2 example

I noticed that the example in the readlink.2 man pages does error
checking for a race condition that would cause the value of the
symbolic link to get larger.  However, it doesn't handle the
opposite case, in which the value gets shorter.  (The NULL
terminator is always set at the old, longer offset.)  This could
cause the program to operate on uninitialized data.

Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
This commit is contained in:
Chuck Coffing 2013-07-15 10:19:29 -06:00 committed by Michael Kerrisk
parent 4b80b37c54
commit c1de8e3e30
1 changed files with 1 additions and 1 deletions

View File

@ -204,7 +204,7 @@ main(int argc, char *argv[])
exit(EXIT_FAILURE);
}
linkname[sb.st_size] = \(aq\\0\(aq;
linkname[r] = \(aq\\0\(aq;
printf("\(aq%s\(aq points to \(aq%s\(aq\\n", argv[1], linkname);