Bug 16469

Summary: pathconf(, _PC_NAME_MAX) returns small value for long Unicode filename on fat FS
Product: File System Reporter: Takumi Asaki (takumi.asaki)
Component: FAT/VFAT/MSDOSAssignee: OGAWA Hirofumi (hirofumi)
Status: CLOSED CODE_FIX    
Severity: normal CC: florian
Priority: P1    
Hardware: All   
OS: Linux   
Kernel Version: 2.6.32-23-generic (ubuntu 10.04) Subsystem:
Regression: No Bisected commit-id:
Attachments: test program
Fix f_namelen

Description Takumi Asaki 2010-07-27 08:29:08 UTC
pathconf(, _PC_NAME_MAX) is too small for long Unicode filename on fat.

255 as max filename size on fat is Unicode UTF-16 characters.
it's not byte size.

When I try to read long Unicode file using readdir() or readdir_r()
they return long string than pathconf(file_on_fat_fs, _PC_NAME_MAX).
And readdir_r() causes buffer overflow when users determine buffer size using pathconf()'s result.

Attached program is to test it.
Please change PWD to a directory on fat FS, and run it.
It create long Unicode filename in PWD, and call readdir_r().
Comment 1 Takumi Asaki 2010-07-27 08:29:57 UTC
Created attachment 27265 [details]
test program
Comment 2 OGAWA Hirofumi 2011-04-12 13:06:02 UTC
Created attachment 54142 [details]
Fix f_namelen

Sorry for long delay.

Attached patch should fix this, and will included future kernel.
But, I'm not pretty sure if there is no userland breakage (for now, 
I didn't found though). Let's see.
Comment 3 Florian Mickler 2011-05-30 07:22:15 UTC
A patch referencing this bug report has been merged in v3.0-rc1:

commit f68e542f3478147986a9c8958942ec649dc06201
Author: OGAWA Hirofumi <hirofumi@mail.parknet.co.jp>
Date:   Tue Apr 12 21:08:39 2011 +0900

    fat: Fix statfs->f_namelen