From nobody Fri Nov 04 14:21:13 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 4N3jV16s3hz4gtWG; Fri, 4 Nov 2022 14:21:13 +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 4N3jV16Jnyz41kp; Fri, 4 Nov 2022 14:21:13 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1667571673; 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=0LEXrO2hJiKXIhVtlJUGfYtyLX9NxdS7pLwPPHq0vbA=; b=Q9P75o6BsQwsuWIHful3G5Dd6HCGsSC7/Z4scuTTZIAmJUCOUnbIgEih8Zm0FMozsWV7fJ MnoiDFbcc6KMohkSQG4HM1OSaayPP26nfHzfB+aoVdAahow1q0/gBU0ktizEKGN0/piv+9 rSBy7KwE8CqLIKKOmOjDA0c8Q4VbUGrBB3zUeANoRuzOSkH4nhgQYO4bzcXoRq63Qyt8ET QmuAhNcdf4jRSeoGghWKnG22AFmVTN25XzecIR+3GrB4t/OlecnpVX+pLm1KkoR0IePn8O xaGLpYV59Jc6h0jpma9UrvxS8WioIzk3ej4moQZqDHsH1U7BlqiriiS4xXp5/Q== 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 4N3jV15NYSz1K6H; Fri, 4 Nov 2022 14:21:13 +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 2A4ELD0k005697; Fri, 4 Nov 2022 14:21:13 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 2A4ELDkL005696; Fri, 4 Nov 2022 14:21:13 GMT (envelope-from git) Date: Fri, 4 Nov 2022 14:21:13 GMT Message-Id: <202211041421.2A4ELDkL005696@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: 8ad7a14ab49b - main - getty: code cleanup, part 1 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: 8ad7a14ab49b93240676e15f404354775be931f4 Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1667571673; 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=0LEXrO2hJiKXIhVtlJUGfYtyLX9NxdS7pLwPPHq0vbA=; b=RSXaN8nj0SoBE5BhC+N1UYgSM/bOgmvFQiUsjpFBxfrZS2fcOZkWhT6GKnHSw8/V+3gyVK CA0UiFkSONVFkgwJZtTSVvllEk1oqCJL0UJHzzR4+kj5uW3kyIiMULXolFQ93YD0J62OsK 6JOv6agcEVM3eZdpCHxAjXSQbykf7hiqW0eBgIktRjiV2sDmHFd5DNMvakD/k7B6/smfNy PGLZdCA9lxiHTF05LNjOvTLBkHZKqTdNdFkBIW0XdBipsZDzawDrQgygxvIQch2Ty2Hok1 rjEpMyHnA1vMy+K8hFS7Oa+f0U2hXKg2WK/Gai/fWQfdoF9wUMlMZEPonW5RXA== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1667571673; a=rsa-sha256; cv=none; b=sgeOXPiZtp7HichFLLVmpY3/dTGip+hloujkHRkP+ysE1RfFyygzIJcSRelYom0H4YZcDC 2/ni3LuBIsxbdMwt9mPC1kst+ztTwYHkKZyedPMJamCapuE2tGHIiloTcDEwmzNHnlnatR y4jZHsydvjQpeDmBNAm/Se/7fIO87+aI4eszA5TOGfhVYUsxU0+mkvnOuHY2MIrBSu3b+j lBwjIfDE15epSlxEciULHj36PR2sH/h2f0ub2UMSHAmhidj8Vw6329gzstMrbLTWqz5Ewu RmyFCJJSIlZnrtkVrELnI1oIRaNJBUzYPiJ+c2/NLASwnHOHtFW6F1j3KJFMcw== 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=8ad7a14ab49b93240676e15f404354775be931f4 commit 8ad7a14ab49b93240676e15f404354775be931f4 Author: Dag-Erling Smørgrav AuthorDate: 2022-11-04 13:23:33 +0000 Commit: Dag-Erling Smørgrav CommitDate: 2022-11-04 14:19:27 +0000 getty: code cleanup, part 1 * Avoid unnecessary use of `unsigned char *` * Use explicit casts when assigning `unsigned char *` to `char *` or vice versa * Drop unused global variables (and fix memory leak in `gettable()`) * Use `snprintf()` instead of `strcpy()` + `strcat()` * Drop spurious braces in switch Sponsored by: Klara, Inc. Obtained from: Apple OSS Distributions (in part) Differential Revision: https://reviews.freebsd.org/D37263 --- libexec/getty/chat.c | 14 +++++++------- libexec/getty/extern.h | 2 +- libexec/getty/init.c | 2 +- libexec/getty/main.c | 18 +++++++----------- libexec/getty/subr.c | 16 ++++++++++------ 5 files changed, 26 insertions(+), 26 deletions(-) diff --git a/libexec/getty/chat.c b/libexec/getty/chat.c index 0f2def37b028..980a144cdb1d 100644 --- a/libexec/getty/chat.c +++ b/libexec/getty/chat.c @@ -59,10 +59,10 @@ static volatile int alarmed = 0; static void chat_alrm(int); static int chat_unalarm(void); -static int getdigit(unsigned char **, int, int); +static int getdigit(char **, int, int); static char **read_chat(char **); static char *cleanchr(char **, unsigned char); -static const char *cleanstr(const unsigned char *, int); +static const char *cleanstr(const char *, int); static const char *result(int); static int chat_expect(const char *); static int chat_send(char const *); @@ -104,7 +104,7 @@ chat_unalarm(void) */ static int -getdigit(unsigned char **ptr, int base, int max) +getdigit(char **ptr, int base, int max) { int i, val = 0; char * q; @@ -149,10 +149,10 @@ read_chat(char **chatstr) p != NULL; p = strtok(NULL, ws)) { - unsigned char *q, *r; + char *q, *r; /* Read escapes */ - for (q = r = (unsigned char *)p; *r; ++q) + for (q = r = p; *r; ++q) { if (*q == '\\') { @@ -271,9 +271,9 @@ cleanchr(char **buf, unsigned char ch) */ static const char * -cleanstr(const unsigned char *s, int l) +cleanstr(const char *s, int l) { - static unsigned char * tmp = NULL; + static char * tmp = NULL; static int tmplen = 0; if (tmplen < l * 4 + 1) diff --git a/libexec/getty/extern.h b/libexec/getty/extern.h index fbee272d109c..6872acb4f6f7 100644 --- a/libexec/getty/extern.h +++ b/libexec/getty/extern.h @@ -48,7 +48,7 @@ const char *autobaud(void); int delaybits(void); void edithost(const char *); void gendefaults(void); -void gettable(const char *, char *); +void gettable(const char *); void makeenv(char *[]); const char *portselector(void); void set_ttydefaults(int); diff --git a/libexec/getty/init.c b/libexec/getty/init.c index ec911ca7223f..4ff0291c6f46 100644 --- a/libexec/getty/init.c +++ b/libexec/getty/init.c @@ -53,7 +53,7 @@ static char nullstr[] = ""; static char loginprg[] = _PATH_LOGIN; static char datefmt[] = "%+"; -#define M(a) (&omode.c_cc[a]) +#define M(a) (char *)(&omode.c_cc[a]) struct gettystrs gettystrs[] = { { "nx", NULL, NULL }, /* next table */ diff --git a/libexec/getty/main.c b/libexec/getty/main.c index e1420586679b..605be6c9bd56 100644 --- a/libexec/getty/main.c +++ b/libexec/getty/main.c @@ -58,6 +58,7 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include #include #include #include @@ -100,10 +101,7 @@ static char name[MAXLOGNAME*3]; static char ttyn[32]; #define OBUFSIZ 128 -#define TABBUFSIZ 512 -static char defent[TABBUFSIZ]; -static char tabent[TABBUFSIZ]; static const char *tname; static char *env[128]; @@ -191,7 +189,7 @@ main(int argc, char *argv[]) gethostname(hostname, sizeof(hostname) - 1); hostname[sizeof(hostname) - 1] = '\0'; if (hostname[0] == '\0') - strcpy(hostname, "Amnesiac"); + snprintf(hostname, sizeof(hostname), "Amnesiac"); /* * Limit running time to deal with broken or dead lines. @@ -201,7 +199,7 @@ main(int argc, char *argv[]) limit.rlim_cur = GETTY_TIMEOUT; (void)setrlimit(RLIMIT_CPU, &limit); - gettable("default", defent); + gettable("default"); gendefaults(); tname = "default"; if (argc > 1) @@ -215,10 +213,9 @@ main(int argc, char *argv[]) * J. Gettys - MIT Project Athena. */ if (argc <= 2 || strcmp(argv[2], "-") == 0) - strcpy(ttyn, ttyname(STDIN_FILENO)); + snprintf(ttyn, sizeof(ttyn), "%s", ttyname(STDIN_FILENO)); else { - strcpy(ttyn, _PATH_DEV); - strlcat(ttyn, argv[2], sizeof(ttyn)); + snprintf(ttyn, sizeof(ttyn), "%s%s", _PATH_DEV, argv[2]); if (strcmp(argv[0], "+") != 0) { chown(ttyn, 0, 0); chmod(ttyn, 0600); @@ -762,7 +759,7 @@ putf(const char *cp) puts(editedhost); break; - case 'd': { + case 'd': t = (time_t)0; (void)time(&t); if (Lo) @@ -786,7 +783,6 @@ putf(const char *cp) case 'v': puts(kerninfo.version); break; - } case '%': putchr('%'); @@ -804,7 +800,7 @@ dogettytab(void) { /* Read the database entry. */ - gettable(tname, tabent); + gettable(tname); /* * Avoid inheriting the parity values from the default entry diff --git a/libexec/getty/subr.c b/libexec/getty/subr.c index 9958d193aa60..f8637211d424 100644 --- a/libexec/getty/subr.c +++ b/libexec/getty/subr.c @@ -60,8 +60,9 @@ static const char rcsid[] = * Get a table entry. */ void -gettable(const char *name, char *buf) +gettable(const char *name) { + char *buf = NULL; struct gettystrs *sp; struct gettynums *np; struct gettyflags *fp; @@ -155,6 +156,7 @@ gettable(const char *name, char *buf) fp->value = 1 ^ fp->invrt; } } + free(buf); } void @@ -202,13 +204,15 @@ charnames[] = { &SU, &DS, &RP, &FL, &WE, &LN, 0 }; +#define CV(a) (char *)(&tmode.c_cc[a]) + static char * charvars[] = { - &tmode.c_cc[VERASE], &tmode.c_cc[VKILL], &tmode.c_cc[VINTR], - &tmode.c_cc[VQUIT], &tmode.c_cc[VSTART], &tmode.c_cc[VSTOP], - &tmode.c_cc[VEOF], &tmode.c_cc[VEOL], &tmode.c_cc[VSUSP], - &tmode.c_cc[VDSUSP], &tmode.c_cc[VREPRINT], &tmode.c_cc[VDISCARD], - &tmode.c_cc[VWERASE], &tmode.c_cc[VLNEXT], 0 + CV(VERASE), CV(VKILL), CV(VINTR), + CV(VQUIT), CV(VSTART), CV(VSTOP), + CV(VEOF), CV(VEOL), CV(VSUSP), + CV(VDSUSP), CV(VREPRINT), CV(VDISCARD), + CV(VWERASE), CV(VLNEXT), 0 }; void