summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormoritz <moritz@openbsd.org>2006-10-24 17:25:48 +0000
committermoritz <moritz@openbsd.org>2006-10-24 17:25:48 +0000
commit1bf24585731f18ada1bbf682c7320a31270600f6 (patch)
tree241aa9f9955bdc2793385203eb8d5d0b6aa6b469
parentevil AF_ISO and AF_NS references were hiding here, but we'll hunt 'em all down! (diff)
downloadwireguard-openbsd-1bf24585731f18ada1bbf682c7320a31270600f6.tar.xz
wireguard-openbsd-1bf24585731f18ada1bbf682c7320a31270600f6.zip
Check strlen(buf) to be > 0 before accessing buf[strlen(buf)-1].
OK ray@ cloder@
-rw-r--r--lib/libcurses/tinfo/captoinfo.c7
-rw-r--r--sbin/fdisk/misc.c12
2 files changed, 14 insertions, 5 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) {
diff --git a/sbin/fdisk/misc.c b/sbin/fdisk/misc.c
index 6aa71e3558d..3c9be4c0e2c 100644
--- a/sbin/fdisk/misc.c
+++ b/sbin/fdisk/misc.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: misc.c,v 1.16 2005/11/21 01:59:24 krw Exp $ */
+/* $OpenBSD: misc.c,v 1.17 2006/10/24 17:30:45 moritz Exp $ */
/*
* Copyright (c) 1997 Tobias Weingartner
@@ -67,11 +67,14 @@ int
ask_cmd(cmd_t *cmd)
{
char lbuf[100], *cp, *buf;
+ size_t lbuflen;
/* Get input */
if (fgets(lbuf, sizeof lbuf, stdin) == NULL)
errx(1, "eof");
- lbuf[strlen(lbuf)-1] = '\0';
+ lbuflen = strlen(lbuf);
+ if (lbuflen > 0 && lbuf[lbuflen - 1] == '\n')
+ lbuf[lbuflen - 1] = '\0';
/* Parse input */
buf = lbuf;
@@ -90,6 +93,7 @@ ask_num(const char *str, int flags, int dflt, int low, int high,
void (*help)(void))
{
char lbuf[100], *cp;
+ size_t lbuflen;
int num;
do {
@@ -104,7 +108,9 @@ again:
if (fgets(lbuf, sizeof lbuf, stdin) == NULL)
errx(1, "eof");
- lbuf[strlen(lbuf)-1] = '\0';
+ lbuflen = strlen(lbuf);
+ if (lbuflen > 0 && lbuf[lbuflen - 1] == '\n')
+ lbuf[lbuflen - 1] = '\0';
if (help && lbuf[0] == '?') {
(*help)();