From bf6ed41692a49bcbe70ab0629cfc5d207c78544c Mon Sep 17 00:00:00 2001 From: Xin LI Date: Tue, 11 Jun 2019 22:21:29 +0000 Subject: [PATCH] Avoid out of boundary access when checking invalid long filenames. Obtained from: OpenBSD (dir.c,v 1.25) MFC after: 3 days --- sbin/fsck_msdosfs/dir.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/sbin/fsck_msdosfs/dir.c b/sbin/fsck_msdosfs/dir.c index e59536f6b5fc..e56bbf80c6bf 100644 --- a/sbin/fsck_msdosfs/dir.c +++ b/sbin/fsck_msdosfs/dir.c @@ -629,6 +629,15 @@ readDosDirSection(int f, struct bootblock *boot, struct fatEntry *fat, vallfn = NULL; } lidx = *p & LRNOMASK; + if (lidx == 0) { + pwarn("invalid long name\n"); + if (!invlfn) { + invlfn = vallfn; + invcl = valcl; + } + vallfn = NULL; + continue; + } t = longName + --lidx * 13; for (k = 1; k < 11 && t < longName + sizeof(longName); k += 2) {