mirror of
https://github.com/github/codeql.git
synced 2026-05-02 12:15:17 +02:00
C#: ZipSlip - Address review comments.
- Add backticks - Add extra test.
This commit is contained in:
@@ -112,7 +112,7 @@ module ZipSlip {
|
||||
}
|
||||
|
||||
/**
|
||||
* A call to Substring.
|
||||
* A call to `Substring`.
|
||||
*
|
||||
* This is considered a sanitizer because `Substring` may be used to extract a single component
|
||||
* of a path to avoid ZipSlip.
|
||||
|
||||
@@ -59,7 +59,7 @@ namespace ZipSlip
|
||||
foreach (ZipArchiveEntry entry in archive.Entries)
|
||||
{
|
||||
// figure out where we are putting the file
|
||||
string destFilePath = Path.Combine(InstallDir, entry.FullName);
|
||||
String destFilePath = Path.Combine(InstallDir, entry.FullName);
|
||||
|
||||
Directory.CreateDirectory(Path.GetDirectoryName(destFilePath));
|
||||
|
||||
@@ -94,6 +94,15 @@ namespace ZipSlip
|
||||
Console.WriteLine(@"Writing ""{0}""", destFilePath);
|
||||
archiveFileStream.CopyTo(fs);
|
||||
}
|
||||
|
||||
// GOOD: Use substring to pick out single component
|
||||
string fileName = destFilePath.Substring(destFilePath.LastIndexOf("\\"));
|
||||
var fileInfo2 = new FileInfo(fileName);
|
||||
using (FileStream fs = fileInfo2.Open(FileMode.Create))
|
||||
{
|
||||
Console.WriteLine(@"Writing ""{0}""", destFilePath);
|
||||
archiveFileStream.CopyTo(fs);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user