From 6871ed8f8682b635bbd7a844488ec05883e89172 Mon Sep 17 00:00:00 2001 From: deraadt Date: Thu, 2 Dec 2021 15:13:49 +0000 Subject: [PATCH] firstc() and nextc() use an int of global static storage. Make this a pointer to a local variable to allow concurrent use if that ever needs to happen in the future. ok mpi kettenis --- sys/kern/tty.c | 16 +++++++++------- sys/kern/tty_subr.c | 18 ++++++++---------- sys/sys/tty.h | 6 +++--- 3 files changed, 20 insertions(+), 20 deletions(-) diff --git a/sys/kern/tty.c b/sys/kern/tty.c index eaaa4b2a6e4..9dfe18756ed 100644 --- a/sys/kern/tty.c +++ b/sys/kern/tty.c @@ -1,4 +1,4 @@ -/* $OpenBSD: tty.c,v 1.170 2021/10/24 00:02:25 jsg Exp $ */ +/* $OpenBSD: tty.c,v 1.171 2021/12/02 15:13:49 deraadt Exp $ */ /* $NetBSD: tty.c,v 1.68.4.2 1996/06/06 16:04:52 thorpej Exp $ */ /*- @@ -1901,7 +1901,7 @@ ttyrub(int c, struct tty *tp) { u_char *cp; int savecol; - int tabc, s; + int tabc, s, cc; if (!ISSET(tp->t_lflag, ECHO) || ISSET(tp->t_lflag, EXTPROC)) return 0; @@ -1937,8 +1937,8 @@ ttyrub(int c, struct tty *tp) SET(tp->t_state, TS_CNTTB); SET(tp->t_lflag, FLUSHO); tp->t_column = tp->t_rocol; - for (cp = firstc(&tp->t_rawq, &tabc); cp; - cp = nextc(&tp->t_rawq, cp, &tabc)) + for (cp = firstc(&tp->t_rawq, &tabc, &cc); cp; + cp = nextc(&tp->t_rawq, cp, &tabc, &cc)) ttyecho(tabc, tp); CLR(tp->t_lflag, FLUSHO); CLR(tp->t_state, TS_CNTTB); @@ -1995,7 +1995,7 @@ int ttyretype(struct tty *tp) { u_char *cp; - int s, c; + int s, c, cc; /* Echo the reprint character. */ if (tp->t_cc[VREPRINT] != _POSIX_VDISABLE) @@ -2004,9 +2004,11 @@ ttyretype(struct tty *tp) (void)ttyoutput('\n', tp); s = spltty(); - for (cp = firstc(&tp->t_canq, &c); cp; cp = nextc(&tp->t_canq, cp, &c)) + for (cp = firstc(&tp->t_canq, &c, &cc); cp; + cp = nextc(&tp->t_canq, cp, &c, &cc)) ttyecho(c, tp); - for (cp = firstc(&tp->t_rawq, &c); cp; cp = nextc(&tp->t_rawq, cp, &c)) + for (cp = firstc(&tp->t_rawq, &c, &cc); cp; + cp = nextc(&tp->t_rawq, cp, &c, &cc)) ttyecho(c, tp); CLR(tp->t_state, TS_ERASE); splx(s); diff --git a/sys/kern/tty_subr.c b/sys/kern/tty_subr.c index c8bca080ddb..c680d2466a4 100644 --- a/sys/kern/tty_subr.c +++ b/sys/kern/tty_subr.c @@ -1,4 +1,4 @@ -/* $OpenBSD: tty_subr.c,v 1.34 2021/12/01 17:04:26 deraadt Exp $ */ +/* $OpenBSD: tty_subr.c,v 1.35 2021/12/02 15:13:49 deraadt Exp $ */ /* $NetBSD: tty_subr.c,v 1.13 1996/02/09 19:00:43 christos Exp $ */ /* @@ -346,8 +346,6 @@ out: return count; } -static int cc; - /* * Given a non-NULL pointer into the clist return the pointer * to the next character in the list or return NULL if no more chars. @@ -357,18 +355,18 @@ static int cc; * masked. */ u_char * -nextc(struct clist *clp, u_char *cp, int *c) +nextc(struct clist *clp, u_char *cp, int *c, int *ccp) { if (clp->c_cf == cp) { /* * First time initialization. */ - cc = clp->c_cc; + *ccp = clp->c_cc; } - if (cc == 0 || cp == NULL) + if (*ccp == 0 || cp == NULL) return NULL; - if (--cc == 0) + if (--(*ccp) == 0) return NULL; if (++cp == clp->c_ce) cp = clp->c_cs; @@ -391,12 +389,12 @@ nextc(struct clist *clp, u_char *cp, int *c) * *c is set to the NEXT character */ u_char * -firstc(struct clist *clp, int *c) +firstc(struct clist *clp, int *c, int *ccp) { u_char *cp; - cc = clp->c_cc; - if (cc == 0) + *ccp = clp->c_cc; + if (*ccp == 0) return NULL; cp = clp->c_cf; *c = *cp & 0xff; diff --git a/sys/sys/tty.h b/sys/sys/tty.h index cce15817321..b31aeec35d9 100644 --- a/sys/sys/tty.h +++ b/sys/sys/tty.h @@ -1,4 +1,4 @@ -/* $OpenBSD: tty.h,v 1.39 2020/07/14 14:33:06 deraadt Exp $ */ +/* $OpenBSD: tty.h,v 1.40 2021/12/02 15:13:49 deraadt Exp $ */ /* $NetBSD: tty.h,v 1.30.4.1 1996/06/02 09:08:13 mrg Exp $ */ /*- @@ -260,7 +260,8 @@ void clist_init(void); int getc(struct clist *q); void ndflush(struct clist *q, int cc); int ndqb(struct clist *q, int flag); -u_char *nextc(struct clist *q, u_char *cp, int *c); +u_char *firstc(struct clist *clp, int *c, int *cc); +u_char *nextc(struct clist *q, u_char *cp, int *c, int *cc); int putc(int c, struct clist *q); int q_to_b(struct clist *q, u_char *cp, int cc); int unputc(struct clist *q); @@ -300,7 +301,6 @@ void ttytstamp(struct tty *tp, int octs, int ncts, int odcd, int ndcd); void tty_init(void); struct tty *ttymalloc(int); void ttyfree(struct tty *); -u_char *firstc(struct clist *clp, int *c); int cttyopen(dev_t, int, int, struct proc *); int cttyread(dev_t, struct uio *, int); -- 2.20.1