From mboxrd@z Thu Jan 1 00:00:00 1970 From: Matthew Daley Subject: [PATCH v2] xenconsole: merge pty access check into when it is opened Date: Mon, 2 Dec 2013 15:41:38 +1300 Message-ID: <1385952098-30095-1-git-send-email-mattd@bugfuzz.com> References: <529BC659.8010602@citrix.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: <529BC659.8010602@citrix.com> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: xen-devel@lists.xen.org Cc: Andrew Cooper , Matthew Daley , Ian Jackson , Ian Campbell , Stefano Stabellini List-Id: xen-devel@lists.xenproject.org This stops pty_path from being leaked, and removes the toctou race, FWIW. Not sure why it's a separate check to begin with... Coverity-ID: 1056047 Signed-off-by: Matthew Daley --- v2: err() if open() fails with EACCES as well tools/console/client/main.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/tools/console/client/main.c b/tools/console/client/main.c index 38c856a..3242008 100644 --- a/tools/console/client/main.c +++ b/tools/console/client/main.c @@ -116,12 +116,9 @@ static int get_pty_fd(struct xs_handle *xs, char *path, int seconds) * disambiguate: just read the pty path */ pty_path = xs_read(xs, XBT_NULL, path, &len); if (pty_path != NULL) { - if (access(pty_path, R_OK|W_OK) != 0) - continue; pty_fd = open(pty_path, O_RDWR | O_NOCTTY); - if (pty_fd == -1) - err(errno, "Could not open tty `%s'", - pty_path); + if (pty_fd == -1) + err(errno, "Could not open tty `%s'", pty_path); free(pty_path); } } -- 1.7.10.4