summaryrefslogtreecommitdiffstats
path: root/src/fat_dir.c
diff options
context:
space:
mode:
authorChristophe Grenier <grenier@cgsecurity.org>2010-09-24 08:11:58 +0200
committerChristophe Grenier <grenier@cgsecurity.org>2010-09-24 08:11:58 +0200
commit0e447e5b07c3d5771353b997884ba7209fc5e6d3 (patch)
tree38d1ddd4a13330c6a3b6b00fc67534c5b400f124 /src/fat_dir.c
parentdf47ee18e5f97cf64aa69cfe0c05732e1ff9b184 (diff)
Assume utf8 filenames in FAT
Diffstat (limited to 'src/fat_dir.c')
-rw-r--r--src/fat_dir.c24
1 files changed, 20 insertions, 4 deletions
diff --git a/src/fat_dir.c b/src/fat_dir.c
index 2c3c4d3..2e83ff3 100644
--- a/src/fat_dir.c
+++ b/src/fat_dir.c
@@ -80,6 +80,8 @@ file_data_t *dir_fat_aux(const unsigned char*buffer, const unsigned int size, co
file_data_t *current_file=NULL;
unsigned int status;
unsigned int inode;
+ int utf8=1;
+ wctomb(NULL, 0);
GetNew:
status=0;
long_slots = 0;
@@ -256,11 +258,25 @@ RecEnd:
return dir_list;
if((int8_t) unicode[0] != (int8_t) DELETED_FLAG)
{
- unsigned int i;
+ unsigned int i,o;
file_data_t *new_file=(file_data_t *)MALLOC(sizeof(*new_file));
- for(i=0;(unicode[i]!=0)&&(i<sizeof(new_file->name)-1);i++)
- new_file->name[i]=(char) unicode[i];
- new_file->name[i]=0;
+ for(i=0,o=0; unicode[i]!=0 && o<sizeof(new_file->name)-1; i++)
+ {
+ if(utf8 && unicode[i]>0x7f)
+ {
+ const int sizec=wctomb(&new_file->name[o], unicode[i]);
+ if(sizec <= 0)
+ {
+ new_file->name[o]=(char) unicode[i];
+ utf8=0;
+ }
+ else
+ o += sizec;
+ }
+ else
+ new_file->name[o++]=(char) unicode[i];
+ }
+ new_file->name[o]=0;
new_file->stat.st_dev=0;
new_file->stat.st_ino=inode;
new_file->stat.st_mode = MSDOS_MKMODE(de->attr,(LINUX_S_IRWXUGO & ~(LINUX_S_IWGRP|LINUX_S_IWOTH)));