close(2) should be called after errno is examined as close may change errno variable.
Details
- Reviewers
kib - Commits
- rG741d78126b55: rtld: call close(2) after errno is saved
No functional changes intended.
Diff Detail
- Repository
- rG FreeBSD src repository
- Lint
Lint Skipped - Unit
Tests Skipped
Event Timeline
In principle close() might obliterate errno, so rtld_strerror() call in dbg() inside the check becomes corrupted.
Oh, that means the current (in repo) code is wrong anyway. close(2) should be then called just before return.
Well, then free() can obliterate errno as well.
I suggest to return to your initial patch, with some modifications.
Note that errno is not set by read(2) unless return value is -1, while code checks both for errors, EOFs, and short reads.
Save the value of errno somewhere if read returned -1, and then use the saved value in dbg().
Fix similar problems in different locations. Save original errno value from function it originally generated it.
Please use diff -U99999999 when generating patch, to add context to the review.
libexec/rtld-elf/libmap.c | ||
---|---|---|
106 | We call such variable saved_errno in other places. | |
142 | I suggest to issue different dbg() statements for case retval == -1 and retval >= 0. In the first case, use saved_errno, in second report something like 'short read' and print expected and returned lengths. |