Skip to contentSkip to conversation

VFAT fix for UTF-8 and trailing dots

PATCH In review Michal Rokos 2 participants 4 messages Dec 6, 2003

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 VFAT fix for UTF-8 and trailing dots

Hello all,

there is one problem with vfat when UTF-8 option is on...

The problem is: even if vfat_striptail_len() counts len of name without trailing dots and sets len to the correct value, utf8_mbstowcs() doesn't care about len and takes whole name.
So dirs and files with dots can be created on vfat fs and that will cause some problems as you know :)

This patch just shortens outlen to the correct value - nothing else.

Compiled, tested.

Please concider the inclusion.

Thank you.

Michal

fs/vfat/namei.c renamed from fs/vfat/namei.c.old +9 -4
@@ -573,13 +573,18 @@ xlate_to_uni(const unsigned char *name, 
 	int charlen;
 
 	if (utf8) {
+		int name_len = strlen(name);
+
 		*outlen = utf8_mbstowcs((wchar_t *)outname, name, PAGE_SIZE);
-		if (name[len-1] == '.')
-			*outlen-=2;
+
+		/* 
+		 * We stripped '.'s before and set len appropriately,
+		 * but utf8_mbstowcs doesn't care about len
+		 */
+		*outlen -= (name_len-len);
+
 		op = &outname[*outlen * sizeof(wchar_t)];
 	} else {
-		if (name[len-1] == '.') 
-			len--;
 		if (nls) {
 			for (i = 0, ip = name, op = outname, *outlen = 0;
 			     i < len && *outlen <= 260; *outlen += 1)
Signature · 4 lines
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Michal Rokos                         Czech Technical University, Prague
e-mail: [email protected]    icq: 36118339     jabber: [email protected]
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
#1 lore raw
Quoted 5 lines · Michal Rokos

The problem is: even if vfat_striptail_len() counts len of name without trailing dots and sets len to the correct value, utf8_mbstowcs() doesn't care about len and takes whole name.
So dirs and files with dots can be created on vfat fs and that will cause some problems as you know :)

[...]

Quoted 4 lines
fs/vfat/namei.c renamed from fs/vfat/namei.c.old +2 -0
 	if (utf8) {
+		int name_len = strlen(name);
+
 		*outlen = utf8_mbstowcs((wchar_t *)outname, name, PAGE_SIZE);

fs/vfat/namei.c xlate_to_uni(const unsigned char *name, · line 586

Quoted 10 lines
fs/vfat/namei.c renamed from fs/vfat/namei.c.old +7 -2
-		if (name[len-1] == '.')
-			*outlen-=2;
+
+		/* 
+		 * We stripped '.'s before and set len appropriately,
+		 * but utf8_mbstowcs doesn't care about len
+		 */
+		*outlen -= (name_len-len);
+
 		op = &outname[*outlen * sizeof(wchar_t)];

Indeed. However, this looks not right fix. I think utf8_mbstowcs() should take the length of both outname and name, so we should fix the utf8_mbstowcs().

For example, utf8_mbstowcs(outbuf, outlen, inbuf, inlen);

Thanks.

Signature · 1 line
OGAWA Hirofumi <[email protected]>
#2 lore raw

Hi,

Quoted 20 lines · OGAWA Hirofumi
Quoted 5 lines · Michal Rokos

The problem is: even if vfat_striptail_len() counts len of name without trailing dots and sets len to the correct value, utf8_mbstowcs() doesn't care about len and takes whole name.
So dirs and files with dots can be created on vfat fs and that will cause some problems as you know :)

[...]

Quoted 10 lines
(quoted diff) +6 -2
 	if (utf8) {
+		int name_len = strlen(name);
+
 		*outlen = utf8_mbstowcs((wchar_t *)outname, name, PAGE_SIZE);
-		if (name[len-1] == '.')
-			*outlen-=2;
+
+		/* 
+		 * We stripped '.'s before and set len appropriately,
+		 * but utf8_mbstowcs doesn't care about len
Quoted 8 lines

Review

Quoted 4 lines
(quoted diff) +3 -0
+		 */
+		*outlen -= (name_len-len);
+
 		op = &outname[*outlen * sizeof(wchar_t)];

Indeed. However, this looks not right fix. I think utf8_mbstowcs() should take the length of both outname and name, so we should fix the utf8_mbstowcs().

I don't know... Functions in nls_base.c have specification the same as those from userspace (defined by ISO/ANSI C or UNIX98).

Probably we should. This was meant as minimal patch.

In case you'll be modifiing nls_base.c, please, decide whether this shouldn't be in...

fs/nls/nls_base.c renamed from fs/nls/nls_base.c.old +1 -0
@@ -99,6 +99,7 @@ utf8_mbstowcs(wchar_t *pwcs, const __u8 
 			}
 		} else {
 			*op++ = *ip++;
+			n--;
 		}
 	}
 	return (op - pwcs);
Quoted 3 lines

For example, utf8_mbstowcs(outbuf, outlen, inbuf, inlen);

I'd would propose uft8_mbsntowcs(outbuf, outlen, inbuf, inlen);

BR

Michal

Signature · 4 lines
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Michal Rokos                         Czech Technical University, Prague
e-mail: [email protected]    icq: 36118339     jabber: [email protected]
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
#3 lore raw
Quoted 20 lines · Michal Rokos

I don't know... Functions in nls_base.c have specification the same as those from userspace (defined by ISO/ANSI C or UNIX98).

Probably we should. This was meant as minimal patch.

In case you'll be modifiing nls_base.c, please, decide whether this shouldn't be in...

fs/nls/nls_base.c renamed from fs/nls/nls_base.c.old +1 -0
@@ -99,6 +99,7 @@ utf8_mbstowcs(wchar_t *pwcs, const __u8 
 			}
 		} else {
 			*op++ = *ip++;
+			n--;
 		}
 	}
 	return (op - pwcs);
Quoted 1 line
Quoted 4 lines
Quoted 2 lines

For example, utf8_mbstowcs(outbuf, outlen, inbuf, inlen);

I'd would propose uft8_mbsntowcs(outbuf, outlen, inbuf, inlen);

Whoops, sorry. You are right.

But I really like the interface like iconv() than this. And current nls interfaces also...

Anyway, I think your patches fix some bugs right now. I'll submit the your both patches.

Thanks.

Signature · 1 line
OGAWA Hirofumi <[email protected]>