From owner-dev-commits-src-all@freebsd.org Sat Jan 9 01:04:21 2021 Return-Path: Delivered-To: dev-commits-src-all@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 654B64DC032; Sat, 9 Jan 2021 01:04:21 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4DCMF12Pcqz3n77; Sat, 9 Jan 2021 01:04:21 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 43CEE4FD0; Sat, 9 Jan 2021 01:04:21 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 10914LCi061614; Sat, 9 Jan 2021 01:04:21 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 10914LXZ061613; Sat, 9 Jan 2021 01:04:21 GMT (envelope-from git) Date: Sat, 9 Jan 2021 01:04:21 GMT Message-Id: <202101090104.10914LXZ061613@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Konstantin Belousov Subject: git: 01839668ce4b - stable/12 - rtld: call close(2) after errno is saved MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: kib X-Git-Repository: src X-Git-Refname: refs/heads/stable/12 X-Git-Reftype: branch X-Git-Commit: 01839668ce4b594c9495911549abde86878a708d Auto-Submitted: auto-generated X-BeenThere: dev-commits-src-all@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Commit messages for all branches of the src repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 09 Jan 2021 01:04:21 -0000 The branch stable/12 has been updated by kib: URL: https://cgit.FreeBSD.org/src/commit/?id=01839668ce4b594c9495911549abde86878a708d commit 01839668ce4b594c9495911549abde86878a708d Author: Konstantin Belousov AuthorDate: 2021-01-01 22:24:46 +0000 Commit: Konstantin Belousov 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;