summaryrefslogtreecommitdiffstats
path: root/usr.bin/mg/cscope.c
diff options
context:
space:
mode:
authorsunil <sunil@openbsd.org>2016-01-19 14:51:00 +0000
committersunil <sunil@openbsd.org>2016-01-19 14:51:00 +0000
commitc21829f47dd1f1372238b64dc193a39cacbe8267 (patch)
treee9e56f088383fe5da279eaafbe6220d1a98b7d1e /usr.bin/mg/cscope.c
parentBring code into line with man page and usage() by only allowing one (diff)
downloadwireguard-openbsd-c21829f47dd1f1372238b64dc193a39cacbe8267.tar.xz
wireguard-openbsd-c21829f47dd1f1372238b64dc193a39cacbe8267.zip
Bounds check while stripping trailing slashes. From max at
max-fillinger.net. Ok lum@
Diffstat (limited to 'usr.bin/mg/cscope.c')
-rw-r--r--usr.bin/mg/cscope.c4
1 files changed, 2 insertions, 2 deletions
diff --git a/usr.bin/mg/cscope.c b/usr.bin/mg/cscope.c
index 02fca962aa1..d84ec7faa1f 100644
--- a/usr.bin/mg/cscope.c
+++ b/usr.bin/mg/cscope.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: cscope.c,v 1.15 2016/01/19 11:39:06 sunil Exp $ */
+/* $OpenBSD: cscope.c,v 1.16 2016/01/19 14:51:00 sunil Exp $ */
/*
* This file is in the public domain.
@@ -614,7 +614,7 @@ csexists(const char *cmd)
continue;
dlen = strlen(dir);
- while (dir[dlen-1] == '/')
+ while (dlen > 0 && dir[dlen-1] == '/')
dir[--dlen] = '\0'; /* strip trailing '/' */
len = snprintf(fname, sizeof(fname), "%s/%s", dir, cmd);