git: 01839668ce4b - stable/12 - rtld: call close(2) after errno is saved
Konstantin Belousov
kib at FreeBSD.org
Sat Jan 9 01:04:21 UTC 2021
The branch stable/12 has been updated by kib:
URL: https://cgit.FreeBSD.org/src/commit/?id=01839668ce4b594c9495911549abde86878a708d
commit 01839668ce4b594c9495911549abde86878a708d
Author: Konstantin Belousov <kib at FreeBSD.org>
AuthorDate: 2021-01-01 22:24:46 +0000
Commit: Konstantin Belousov <kib at FreeBSD.org>
CommitDate: 2021-01-09 01:02:22 +0000
rtld: call close(2) after errno is saved
(cherry picked from commit 741d78126b5584e860811c78f87f51597e375592)
---
libexec/rtld-elf/libmap.c | 17 +++++++++++------
1 file changed, 11 insertions(+), 6 deletions(-)
diff --git a/libexec/rtld-elf/libmap.c b/libexec/rtld-elf/libmap.c
index 627928a9a61b..8ff28af260f3 100644
--- a/libexec/rtld-elf/libmap.c
+++ b/libexec/rtld-elf/libmap.c
@@ -102,7 +102,7 @@ lmc_parse_file(const char *path)
char *lm_map;
struct stat st;
ssize_t retval;
- int fd;
+ int fd, saved_errno;
TAILQ_FOREACH(p, &lmc_head, next) {
if (strcmp(p->path, path) == 0)
@@ -116,9 +116,9 @@ lmc_parse_file(const char *path)
return;
}
if (fstat(fd, &st) == -1) {
- close(fd);
dbg("lm_parse_file: fstat(\"%s\") failed, %s", path,
rtld_strerror(errno));
+ close(fd);
return;
}
@@ -131,14 +131,19 @@ lmc_parse_file(const char *path)
lm_map = xmalloc(st.st_size);
retval = read(fd, lm_map, st.st_size);
+ saved_errno = errno;
+ close(fd);
if (retval != st.st_size) {
- close(fd);
+ if (retval == -1) {
+ dbg("lm_parse_file: read(\"%s\") failed, %s", path,
+ rtld_strerror(saved_errno));
+ } else {
+ dbg("lm_parse_file: short read(\"%s\"), %zd vs %jd",
+ path, retval, (uintmax_t)st.st_size);
+ }
free(lm_map);
- dbg("lm_parse_file: read(\"%s\") failed, %s", path,
- rtld_strerror(errno));
return;
}
- close(fd);
p = xmalloc(sizeof(struct lmc));
p->path = xstrdup(path);
p->dev = st.st_dev;
More information about the dev-commits-src-all
mailing list