From 663425ee48edfb2b3f24c6d47c4ef3a990b44656 Mon Sep 17 00:00:00 2001 From: Chad Loder Date: Fri, 13 Oct 2006 02:11:29 +0000 Subject: Fix another potentially unsafe instance of foo[strlen(foo) - 1] = '\0'. OK krw --- sbin/scsi/scsi.c | 7 +++++-- 1 file 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", -- cgit v1.2.3