summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChad Loder <cloder@cvs.openbsd.org>2006-10-13 02:11:29 +0000
committerChad Loder <cloder@cvs.openbsd.org>2006-10-13 02:11:29 +0000
commit663425ee48edfb2b3f24c6d47c4ef3a990b44656 (patch)
treee7b35c1a0f99731b28c48784e2f3bfab8c1ea513
parentd879b6d45e2562a15d3b158bb807ab2f18d43ebb (diff)
Fix another potentially unsafe instance of foo[strlen(foo) - 1] = '\0'.
OK krw
-rw-r--r--sbin/scsi/scsi.c7
1 files changed, 5 insertions, 2 deletions
diff --git a/sbin/scsi/scsi.c b/sbin/scsi/scsi.c
index 35526a380d7..eea7caee0ea 100644
--- a/sbin/scsi/scsi.c
+++ b/sbin/scsi/scsi.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: scsi.c,v 1.22 2006/10/10 21:38:16 cloder Exp $ */
+/* $OpenBSD: scsi.c,v 1.23 2006/10/13 02:11:28 cloder Exp $ */
/* $FreeBSD: scsi.c,v 1.11 1996/04/06 11:00:28 joerg Exp $ */
/*
@@ -621,10 +621,13 @@ edit_get(void *hook, char *name)
if (editinfo[editind].can_edit) {
char line[80];
+ size_t len;
if (fgets(line, sizeof(line), edit_file) == NULL)
err(errno, "fgets");
- line[strlen(line) - 1] = 0;
+ len = strlen(line);
+ if (len && line[len - 1] == '\n')
+ line[len - 1] = '\0';
if (strncmp(name, line, strlen(name)) != 0) {
fprintf(stderr, "Expected \"%s\" and read \"%s\"\n",