From 65746b0ce6d3eef9e8b7196bbbe03cc7f6b5b9a5 Mon Sep 17 00:00:00 2001 From: millert Date: Tue, 14 Apr 2015 02:24:17 +0000 Subject: [PATCH] Log a more useful error message if ttyname() fails. OK deraadt@ --- libexec/getty/main.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/libexec/getty/main.c b/libexec/getty/main.c index 4071b140169..24189db141c 100644 --- a/libexec/getty/main.c +++ b/libexec/getty/main.c @@ -1,4 +1,4 @@ -/* $OpenBSD: main.c,v 1.35 2015/01/16 05:53:49 deraadt Exp $ */ +/* $OpenBSD: main.c,v 1.36 2015/04/14 02:24:17 millert Exp $ */ /*- * Copyright (c) 1980, 1993 @@ -185,7 +185,15 @@ main(int argc, char *argv[]) * J. Gettys - MIT Project Athena. */ if (argc <= 2 || strcmp(argv[2], "-") == 0) { - snprintf(ttyn, sizeof ttyn, "%s", ttyname(0)); + if ((tname = ttyname(0)) == NULL) { + syslog(LOG_ERR, "stdin: %m"); + exit(1); + } + if (strlcpy(ttyn, tname, sizeof(ttyn)) >= sizeof(ttyn)) { + errno = ENAMETOOLONG; + syslog(LOG_ERR, "%s: %m", tname); + exit(1); + } } else { int i; -- 2.20.1