Fix Xbox FAT directory traversal.

This commit is contained in:
2019-04-10 22:38:35 +01:00
parent bde8280435
commit d2e3856bae
2 changed files with 4 additions and 15 deletions

View File

@@ -51,7 +51,7 @@ namespace DiscImageChef.Filesystems.FATX
return Errno.NoError; return Errno.NoError;
} }
string cutPath = path.StartsWith("/") ? path.Substring(0).ToLower(cultureInfo) : path.ToLower(cultureInfo); string cutPath = path.StartsWith("/") ? path.Substring(1).ToLower(cultureInfo) : path.ToLower(cultureInfo);
if(directoryCache.TryGetValue(cutPath, out Dictionary<string, DirectoryEntry> currentDirectory)) if(directoryCache.TryGetValue(cutPath, out Dictionary<string, DirectoryEntry> currentDirectory))
{ {
@@ -83,18 +83,7 @@ namespace DiscImageChef.Filesystems.FATX
currentPath = p == 0 ? pieces[0] : $"{currentPath}/{pieces[p]}"; currentPath = p == 0 ? pieces[0] : $"{currentPath}/{pieces[p]}";
uint currentCluster = entry.Value.firstCluster; uint currentCluster = entry.Value.firstCluster;
if(directoryCache.TryGetValue(currentPath, out currentDirectory)) if(directoryCache.TryGetValue(currentPath, out currentDirectory)) continue;
{
if(p == pieces.Length - 1) break;
entry = currentDirectory.FirstOrDefault(t => t.Key.ToLower(cultureInfo) == pieces[p]);
if(string.IsNullOrEmpty(entry.Key)) return Errno.NoSuchFile;
if(!entry.Value.attributes.HasFlag(Attributes.Directory)) return Errno.NotDirectory;
continue;
}
uint[] clusters = GetClusters(currentCluster); uint[] clusters = GetClusters(currentCluster);

View File

@@ -55,9 +55,9 @@ namespace DiscImageChef.Filesystems.FATX
bool mounted; bool mounted;
Dictionary<string, DirectoryEntry> rootDirectory; Dictionary<string, DirectoryEntry> rootDirectory;
uint sectorsPerCluster; uint sectorsPerCluster;
FileSystemInfo stat; FileSystemInfo statfs;
Superblock superblock;
Superblock superblock;
public FileSystemType XmlFsType { get; private set; } public FileSystemType XmlFsType { get; private set; }
public Encoding Encoding { get; private set; } public Encoding Encoding { get; private set; }
public string Name => "FATX Filesystem Plugin"; public string Name => "FATX Filesystem Plugin";