From owner-dev-commits-src-all@freebsd.org Sat Jan 16 11:58:24 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 AF97A4DC363; Sat, 16 Jan 2021 11:58:24 +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 "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4DHxQS4RdKz3jfx; Sat, 16 Jan 2021 11:58:24 +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 8B6BF66B1; Sat, 16 Jan 2021 11:58:24 +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 10GBwOeJ093100; Sat, 16 Jan 2021 11:58:24 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 10GBwO66093099; Sat, 16 Jan 2021 11:58:24 GMT (envelope-from git) Date: Sat, 16 Jan 2021 11:58:24 GMT Message-Id: <202101161158.10GBwO66093099@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Mariusz Zaborski Subject: git: 6e8062c855d1 - main - cat: persistent errno MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: oshogbo X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 6e8062c855d19d1cbbd65b6843449f22791c3a0a 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, 16 Jan 2021 11:58:24 -0000 The branch main has been updated by oshogbo: URL: https://cgit.FreeBSD.org/src/commit/?id=6e8062c855d19d1cbbd65b6843449f22791c3a0a commit 6e8062c855d19d1cbbd65b6843449f22791c3a0a Author: Mariusz Zaborski AuthorDate: 2021-01-16 11:55:42 +0000 Commit: Mariusz Zaborski CommitDate: 2021-01-16 11:55:42 +0000 cat: persistent errno There is no guarantee that after close(2)/free the errno will remain persistent. The caller of the udom_open function depends on the errno for reporting errors. Reviewed by: markj Differential Revision: https://reviews.freebsd.org/D28185 --- bin/cat/cat.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/bin/cat/cat.c b/bin/cat/cat.c index cdfc983610de..8ba6f6261ad4 100644 --- a/bin/cat/cat.c +++ b/bin/cat/cat.c @@ -429,7 +429,7 @@ udom_open(const char *path, int flags) struct addrinfo hints, *res, *res0; char rpath[PATH_MAX]; int fd = -1; - int error; + int error, serrno; cap_rights_t rights; /* @@ -453,18 +453,23 @@ udom_open(const char *path, int flags) fd = socket(res->ai_family, res->ai_socktype, res->ai_protocol); if (fd < 0) { + serrno = errno; freeaddrinfo(res0); + errno = serrno; return (-1); } if (caph_rights_limit(fd, &rights) < 0) { + serrno = errno; close(fd); freeaddrinfo(res0); + errno = serrno; return (-1); } error = cap_connect(capnet, fd, res->ai_addr, res->ai_addrlen); if (error == 0) break; else { + serrno = errno; close(fd); fd = -1; } @@ -492,9 +497,13 @@ udom_open(const char *path, int flags) cap_rights_clear(&rights, CAP_CONNECT, CAP_SHUTDOWN); if (caph_rights_limit(fd, &rights) < 0) { + serrno = errno; close(fd); + errno = serrno; return (-1); } + } else { + errno = serrno; } return (fd); }