From 6a697e54feb66336062598370441c888cc8ca31c Mon Sep 17 00:00:00 2001 From: jsg Date: Tue, 27 Jun 2017 12:10:21 +0000 Subject: [PATCH] Avoid the possibility of accessing an array out of bounds. Found with cppcheck. ok krw@ --- sbin/fsck_msdos/dir.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/sbin/fsck_msdos/dir.c b/sbin/fsck_msdos/dir.c index 5ab153d5e3c..7397e574b13 100644 --- a/sbin/fsck_msdos/dir.c +++ b/sbin/fsck_msdos/dir.c @@ -1,4 +1,4 @@ -/* $OpenBSD: dir.c,v 1.30 2015/12/10 17:26:59 mmcc Exp $ */ +/* $OpenBSD: dir.c,v 1.31 2017/06/27 12:10:21 jsg Exp $ */ /* $NetBSD: dir.c,v 1.11 1997/10/17 11:19:35 ws Exp $ */ /* @@ -593,6 +593,8 @@ readDosDirSection(int f, struct bootblock *boot, struct fatEntry *fat, dirent.name[8] = '\0'; for (k = 7; k >= 0 && dirent.name[k] == ' '; k--) dirent.name[k] = '\0'; + if (k < 0) + k = 0; if (dirent.name[k] != '\0') k++; if (dirent.name[0] == SLOT_E5) -- 2.20.1