summaryrefslogtreecommitdiff
path: root/lib/libcurses
diff options
context:
space:
mode:
authorMoritz Jodeit <moritz@cvs.openbsd.org>2006-10-24 17:25:49 +0000
committerMoritz Jodeit <moritz@cvs.openbsd.org>2006-10-24 17:25:49 +0000
commit781b3f7a216ba1b0979218aa783352a43fff826a (patch)
treef018594e65fbc4d552578286ac2bd3bf07785566 /lib/libcurses
parent3b093da1a52f9594273cebac6ed7d5326ba02ada (diff)
Check strlen(buf) to be > 0 before accessing buf[strlen(buf)-1].
OK ray@ cloder@
Diffstat (limited to 'lib/libcurses')
-rw-r--r--lib/libcurses/tinfo/captoinfo.c7
1 files changed, 5 insertions, 2 deletions
diff --git a/lib/libcurses/tinfo/captoinfo.c b/lib/libcurses/tinfo/captoinfo.c
index 291cecb0a44..7c6a4587f58 100644
--- a/lib/libcurses/tinfo/captoinfo.c
+++ b/lib/libcurses/tinfo/captoinfo.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: captoinfo.c,v 1.14 2006/10/10 21:38:16 cloder Exp $ */
+/* $OpenBSD: captoinfo.c,v 1.15 2006/10/24 17:25:48 moritz Exp $ */
/****************************************************************************
* Copyright (c) 1998,1999,2000 Free Software Foundation, Inc. *
@@ -817,11 +817,14 @@ main(int argc, char *argv[])
curr_line = 0;
for (;;) {
char buf[BUFSIZ];
+ size_t buflen;
++curr_line;
if (fgets(buf, sizeof(buf), stdin) == NULL)
break;
- buf[strlen(buf) - 1] = '\0';
+ buflen = strlen(buf);
+ if (buflen > 0 && buf[buflen - 1] == '\n')
+ buf[buflen - 1] = '\0';
_nc_set_source(buf);
if (tc) {