Bug 16469 - pathconf(, _PC_NAME_MAX) returns small value for long Unicode filename on fat FS
Summary: pathconf(, _PC_NAME_MAX) returns small value for long Unicode filename on fat FS
Status: CLOSED CODE_FIX
Alias: None
Product: File System
Classification: Unclassified
Component: FAT/VFAT/MSDOS (show other bugs)
Hardware: All Linux
: P1 normal
Assignee: OGAWA Hirofumi
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-07-27 08:29 UTC by Takumi Asaki
Modified: 2011-05-30 07:22 UTC (History)
1 user (show)

See Also:
Kernel Version: 2.6.32-23-generic (ubuntu 10.04)
Subsystem:
Regression: No
Bisected commit-id:


Attachments
test program (1.59 KB, application/octet-stream)
2010-07-27 08:29 UTC, Takumi Asaki
Details
Fix f_namelen (1014 bytes, patch)
2011-04-12 13:06 UTC, OGAWA Hirofumi
Details | Diff

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

Note You need to log in before you can comment on or make changes to this bug.