Skip to content
This repository was archived by the owner on Oct 14, 2021. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,6 @@ public void SetExtension(string value)
[SecuritySafeCritical]
public bool IsValid(string path)
{
if (!IsValidName(path))
{
return false;
}
string ext = SecurityUtils.getFileExtension(path);
for (int i = 0; i < this.whitelist.Count; i++)
{
Expand All @@ -53,23 +49,5 @@ public bool IsEmpty()
return false;
}

private bool IsValidName(string path)
{
int counter = 0;
int i = 0;
while (i < path.Length && counter <= 2)
{
if (path[i] == '.')
{
counter++;
}
i++;
}
if (counter >= 2)
{
return false;
}
return true;
}
}
}
17 changes: 11 additions & 6 deletions dotnet/dotnetframework/SecurityAPICommons/Utils/SecurityUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using Org.BouncyCastle.Utilities.Encoders;
using SecurityAPICommons.Commons;
using System;
using System.IO;
using System.Security;

namespace SecurityAPICommons.Utils
Expand Down Expand Up @@ -49,13 +50,17 @@ public static bool extensionIs(string path, string ext)
[SecuritySafeCritical]
public static string getFileExtension(string path)
{

int lastIndexOf = path.LastIndexOf(".");
if (lastIndexOf == -1)
{
return ""; // empty extension
string fileName = Path.GetFileName(path);
string extension;
try
{
extension = Path.GetExtension(fileName);
}
return path.Substring(lastIndexOf);
catch(Exception)
{
extension = "";
}
return extension;
}

[SecuritySafeCritical]
Expand Down