diff options
author | Theo de Raadt <deraadt@cvs.openbsd.org> | 2019-03-24 05:30:36 +0000 |
---|---|---|
committer | Theo de Raadt <deraadt@cvs.openbsd.org> | 2019-03-24 05:30:36 +0000 |
commit | 69372dcdb1bd1db84628a3e8a336d628f888797f (patch) | |
tree | 2fc22e082860d99f774bddffef6f6962774a66cb /bin/ps | |
parent | 4fbded09ffe97c3e2ed31b477659e28289a54f03 (diff) |
detect -t argument being too long, rather than truncating
Diffstat (limited to 'bin/ps')
-rw-r--r-- | bin/ps/ps.c | 13 |
1 files changed, 8 insertions, 5 deletions
diff --git a/bin/ps/ps.c b/bin/ps/ps.c index 611c1d30e7c..34e12dd56d0 100644 --- a/bin/ps/ps.c +++ b/bin/ps/ps.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ps.c,v 1.74 2019/02/05 18:13:20 florian Exp $ */ +/* $OpenBSD: ps.c,v 1.75 2019/03/24 05:30:35 deraadt Exp $ */ /* $NetBSD: ps.c,v 1.15 1995/05/18 20:33:25 mycroft Exp $ */ /*- @@ -203,10 +203,13 @@ main(int argc, char *argv[]) if (strcmp(optarg, "co") == 0) ttypath = _PATH_CONSOLE; - else if (*optarg != '/') - (void)snprintf(ttypath = pathbuf, - sizeof(pathbuf), "%s%s", _PATH_TTY, optarg); - else + else if (*optarg != '/') { + int r = snprintf(pathbuf, sizeof(pathbuf), "%s%s", + _PATH_TTY, optarg); + if (r < 0 || r > sizeof(pathbuf)) + errx(1, "%s: too long\n", optarg); + ttypath = pathbuf; + } else ttypath = optarg; if (stat(ttypath, &sb) == -1) err(1, "%s", ttypath); |