From 1d09995353dbf92fca45bc15339778e52e564cf2 Mon Sep 17 00:00:00 2001 From: Jacob Moody Date: Sat, 28 May 2022 17:23:41 +0000 Subject: [PATCH] kernel: be more careful about argc for /dev/drivers writes Not crashing on 'chdev &' is important. --- sys/src/9/port/devcons.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/sys/src/9/port/devcons.c b/sys/src/9/port/devcons.c index 756a47936..62387dbbb 100644 --- a/sys/src/9/port/devcons.c +++ b/sys/src/9/port/devcons.c @@ -705,18 +705,22 @@ conswrite(Chan *c, void *va, long n, vlong off) error(Ebadarg); if(ct->index != CMchdev) error(Ebadarg); - if(cb->nf < 2 || cb->nf > 3) + if(cb->nf == 1) error(Ebadarg); invert = 1; - a = cb->f[2]; + a = ""; switch(cb->f[1][0]){ case '&': + if(cb->nf != 3) + error(Ebadarg); + a = cb->f[2]; if(cb->f[1][1] == '~') invert--; break; case '~': - a = ""; + if(cb->nf != 2) + error(Ebadarg); break; default: error(Ebadarg);