summaryrefslogtreecommitdiff
path: root/bin/ps/ps.c
diff options
context:
space:
mode:
Diffstat (limited to 'bin/ps/ps.c')
-rw-r--r--bin/ps/ps.c13
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);