From nobody Fri Nov 04 15:31:45 2022 X-Original-To: dev-commits-src-main@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4N3l3P6lfjz4h3Mk; Fri, 4 Nov 2022 15:31:45 +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 4N3l3P68pJz47m9; Fri, 4 Nov 2022 15:31:45 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1667575905; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=iG8JkBIm3ujHvNEn0HK2CQTuZyDVH8Yd0Pd2ngdcv+w=; b=YZyRbBG/qeedX8Zu744AwaOPAEN7uzBQ7jtma++RzRN8XuOU0SDYSCZUL+H53C+nzHTFCy wJhHupBD9/YxrPTSWd/Pb7eAX8eG6aR8jdh+cs/hTZ2ColfZiV7s7HmK/ccZCEQIGC0SBL U8QmX2JomJpetvVhHGhRHdVz0UyjZTjescUZsgnHXRxoDBywLswQM9nB9TRRDolx7goAPv 2ffRMNVKgNrvBmXFArLJgcPF0e7G7GN7+ACisNpQkOeGFlUzixUbpHGVsebvK4oZE5AVp0 HQYGPVTqs8dr9xWIMAq5lOkoIGYtucS9RJmckkFtBeTZa+ekoLMfHbDPzdAhEQ== 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 4N3l3P5FWVz1LPx; Fri, 4 Nov 2022 15:31:45 +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 2A4FVjao008860; Fri, 4 Nov 2022 15:31:45 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 2A4FVjFZ008858; Fri, 4 Nov 2022 15:31:45 GMT (envelope-from git) Date: Fri, 4 Nov 2022 15:31:45 GMT Message-Id: <202211041531.2A4FVjFZ008858@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: =?utf-8?Q?Dag-Erling=20Sm=C3=B8rgrav?= Subject: git: eb4d86d529e2 - main - getty: Avoid NULL deref if stdin is not a tty. List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-main@freebsd.org X-BeenThere: dev-commits-src-main@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: des X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: eb4d86d529e2523a19fd7454976923319954a49d Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1667575905; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=iG8JkBIm3ujHvNEn0HK2CQTuZyDVH8Yd0Pd2ngdcv+w=; b=ym4g5Utx0s+fRZ++R8xa8GKK5sM042MwW7ZoKybzxuf767mH78yjgy5FmUyDp0dCu8+huv 9DKUqQRDH29aPpigEpokOR/BvQS8bzwfYlGWe0EJoUqJucUh/Nrnalsbe2poIEV/vTa75b kEV8qzjtry65ODAwRnERyKq8o8RDPx0n58lYcPFj+/CX15Y5iqVbMH2JCdqBlCga6dSOqT pKRM1b922CAW6XThQtNIApcDi1KpinYnBbTvPf6OS785q8WKbuF3cl+MNJ4BgRWDMCBfn/ W0y87MAY7U2NthxsBWsnp65i5Rlq/nYJ5Inn/wuxlppH9/CblwHLVrr/EMRPwQ== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1667575905; a=rsa-sha256; cv=none; b=GVKm6TtbgAoCrHtvVfoGWpEnsYsG6xfLIt+htA6QixXxl8Uy6tizKbqbmgcCW8HZ0jkALw mYiqd5CYF1LdHf+yyyJjBwEqHqqbq4e0JsNgri7X94UqZfwEdObPRqYH+i9wZtyYn90hfY XHMRAi2wP3xG2Lj/rzrBrxHb/z4nr7toAXoInQYrAughAEHYwwUj2fAf8HTA4r1HfbL8r1 4izb5PQrjb7ICuqycQEJgCjj1AJVSdbnCtAqe5bALftNLEtUCI4Anm5MghXqB4zqybZT8F YhWeEamTMbKNoGYfMUMnY7w03R+a3CYgLbueJKG4ZagHgpKfNGSh4Eo4iHcOfA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by des: URL: https://cgit.FreeBSD.org/src/commit/?id=eb4d86d529e2523a19fd7454976923319954a49d commit eb4d86d529e2523a19fd7454976923319954a49d Author: Dag-Erling Smørgrav AuthorDate: 2022-11-04 14:43:06 +0000 Commit: Dag-Erling Smørgrav CommitDate: 2022-11-04 14:54:01 +0000 getty: Avoid NULL deref if stdin is not a tty. Sponsored by: Klara, Inc. Obtained from: Apple OSS Distributions Differential Revision: https://reviews.freebsd.org/D37265 --- libexec/getty/main.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/libexec/getty/main.c b/libexec/getty/main.c index bc01ab83b8b2..b8af86c22e92 100644 --- a/libexec/getty/main.c +++ b/libexec/getty/main.c @@ -212,9 +212,14 @@ main(int argc, char *argv[]) * that the file descriptors are already set up for us. * J. Gettys - MIT Project Athena. */ - if (argc <= 2 || strcmp(argv[2], "-") == 0) - snprintf(ttyn, sizeof(ttyn), "%s", ttyname(STDIN_FILENO)); - else { + if (argc <= 2 || strcmp(argv[2], "-") == 0) { + char *n = ttyname(STDIN_FILENO); + if (n == NULL) { + syslog(LOG_ERR, "ttyname: %m"); + exit(1); + } + snprintf(ttyn, sizeof(ttyn), "%s", n); + } else { snprintf(ttyn, sizeof(ttyn), "%s%s", _PATH_DEV, argv[2]); if (strcmp(argv[0], "+") != 0) { chown(ttyn, 0, 0);