mirror of https://github.com/mkerrisk/man-pages
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:
parent
4b80b37c54
commit
c1de8e3e30
|
@ -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);
|
||||
|
||||
|
|
Loading…
Reference in New Issue