Modules/FAT - Fixed unneeded memcpy in LFN, made more robust too
authorJohn Hodge <[email protected]>
Fri, 11 Nov 2011 04:35:16 +0000 (12:35 +0800)
committerJohn Hodge <[email protected]>
Fri, 11 Nov 2011 04:37:47 +0000 (12:37 +0800)
Modules/Filesystems/FAT/fat.c

index 97044eb..f65cb42 100644 (file)
@@ -1352,8 +1352,11 @@ tVFS_Node *FAT_FindDir(tVFS_Node *Node, const char *Name)
                        lfnInfo = (fat_longfilename *) &fileinfo[i&0xF];\r
                        if(lfnInfo->id & 0x40) {\r
                                memset(lfn, 0, 256);\r
-                               lfnPos = 255;\r
+                               lfnPos = (lfnInfo->id & 0x3F) * 13 - 1;\r
                        }\r
+                       // Sanity check the position so we don't overflow\r
+                       if( lfnPos < 12 )\r
+                               continue ;\r
                        lfn[lfnPos--] = lfnInfo->name3[1];      lfn[lfnPos--] = lfnInfo->name3[0];\r
                        lfn[lfnPos--] = lfnInfo->name2[5];      lfn[lfnPos--] = lfnInfo->name2[4];\r
                        lfn[lfnPos--] = lfnInfo->name2[3];      lfn[lfnPos--] = lfnInfo->name2[2];\r
@@ -1363,7 +1366,6 @@ tVFS_Node *FAT_FindDir(tVFS_Node *Node, const char *Name)
                        lfn[lfnPos--] = lfnInfo->name1[0];\r
                        if((lfnInfo->id&0x3F) == 1)\r
                        {\r
-                               memcpy(lfn, lfn+lfnPos+1, 256-lfnPos);\r
                                lfnId = i+1;\r
                        }\r
                }\r

UCC git Repository :: git.ucc.asn.au