fat: fix buffer overflow in vfat_create_shortname()

Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
From: Linux Kernel Mailing List
Date: Thursday, April 1, 2010 - 10:59 am

Gitweb:     http://git.kernel.org/linus/30d1872d9eb3663b4cf7bdebcbf5cd465674cced
Commit:     30d1872d9eb3663b4cf7bdebcbf5cd465674cced
Parent:     2eaa9cfdf33b8d7fb7aff27792192e0019ae8fc6
Author:     Nikolaus Schulz <microschulz@web.de>
AuthorDate: Thu Apr 1 02:21:10 2010 +0900
Committer:  Linus Torvalds <torvalds@linux-foundation.org>
CommitDate: Wed Mar 31 10:34:11 2010 -0700

    fat: fix buffer overflow in vfat_create_shortname()
    
    When using the string representation of a random counter as part of the base
    name, ensure that it is no longer than 4 bytes.
    
    Since we are repeatedly decrementing the counter in a loop until we have found a
    unique base name, the counter may wrap around zero; therefore, it is not enough
    to mask its higher bits before entering the loop, this must be done inside the
    loop.
    
    [hirofumi@mail.parknet.co.jp: use snprintf()]
    Signed-off-by: Nikolaus Schulz <microschulz@web.de>
    Cc: stable@kernel.org
    Signed-off-by: OGAWA Hirofumi <hirofumi@mail.parknet.co.jp>
    Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
---
 fs/fat/namei_vfat.c |    6 +++---
 1 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/fs/fat/namei_vfat.c b/fs/fat/namei_vfat.c
index c1ef501..6fcc7e7 100644
--- a/fs/fat/namei_vfat.c
+++ b/fs/fat/namei_vfat.c
@@ -309,7 +309,7 @@ static int vfat_create_shortname(struct inode *dir, struct nls_table *nls,
 {
 	struct fat_mount_options *opts = &MSDOS_SB(dir->i_sb)->options;
 	wchar_t *ip, *ext_start, *end, *name_start;
-	unsigned char base[9], ext[4], buf[8], *p;
+	unsigned char base[9], ext[4], buf[5], *p;
 	unsigned char charbuf[NLS_MAX_CHARSET_SIZE];
 	int chl, chi;
 	int sz = 0, extlen, baselen, i, numtail_baselen, numtail2_baselen;
@@ -467,7 +467,7 @@ static int vfat_create_shortname(struct inode *dir, struct nls_table *nls,
 			return 0;
 	}
 
-	i = jiffies & 0xffff;
+	i = jiffies;
 	sz = (jiffies >> 16) & 0x7;
 	if (baselen > 2) {
 		baselen = numtail2_baselen;
@@ -476,7 +476,7 @@ static int vfat_create_shortname(struct inode *dir, struct nls_table *nls,
 	name_res[baselen + 4] = '~';
 	name_res[baselen + 5] = '1' + sz;
 	while (1) {
-		sprintf(buf, "%04X", i);
+		snprintf(buf, sizeof(buf), "%04X", i & 0xffff);
 		memcpy(&name_res[baselen], buf, 4);
 		if (vfat_find_form(dir, name_res) < 0)
 			break;
--
To unsubscribe from this list: send the line "unsubscribe git-commits-head" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
fat: fix buffer overflow in vfat_create_shortname(), Linux Kernel Mailing ..., (Thu Apr 1, 10:59 am)