зеркало из https://github.com/mono/ikvm-fork.git
Added parameter validation to ikvmc's -version option (fix bug #2987144 ).
This commit is contained in:
Родитель
08f9a0706a
Коммит
a2dd178187
|
@ -214,7 +214,7 @@ class IkvmcCompiler
|
|||
CompilerOptions options = new CompilerOptions();
|
||||
options.target = PEFileKinds.ConsoleApplication;
|
||||
options.guessFileKind = true;
|
||||
options.version = "0.0.0.0";
|
||||
options.version = new Version(0, 0, 0, 0);
|
||||
options.apartment = ApartmentState.STA;
|
||||
options.props = new Dictionary<string, string>();
|
||||
return ContinueParseCommandLine(arglist, targets, options);
|
||||
|
@ -485,30 +485,11 @@ class IkvmcCompiler
|
|||
}
|
||||
else if(s.StartsWith("-version:"))
|
||||
{
|
||||
options.version = s.Substring(9);
|
||||
if(options.version.EndsWith(".*"))
|
||||
string str = s.Substring(9);
|
||||
if(!TryParseVersion(s.Substring(9), out options.version))
|
||||
{
|
||||
options.version = options.version.Substring(0, options.version.Length - 1);
|
||||
int count = options.version.Split('.').Length;
|
||||
// NOTE this is the published algorithm for generating automatic build and revision numbers
|
||||
// (see AssemblyVersionAttribute constructor docs), but it turns out that the revision
|
||||
// number is off an hour (on my system)...
|
||||
DateTime now = DateTime.Now;
|
||||
int seconds = (int)(now.TimeOfDay.TotalSeconds / 2);
|
||||
int days = (int)(now - new DateTime(2000, 1, 1)).TotalDays;
|
||||
if(count == 3)
|
||||
{
|
||||
options.version += days + "." + seconds;
|
||||
}
|
||||
else if(count == 4)
|
||||
{
|
||||
options.version += seconds;
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.Error.WriteLine("Error: Invalid version specified: {0}*", options.version);
|
||||
return 1;
|
||||
}
|
||||
Console.Error.WriteLine("Error: Invalid version specified: {0}", str);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
else if(s.StartsWith("-fileversion:"))
|
||||
|
@ -720,6 +701,44 @@ class IkvmcCompiler
|
|||
return 0;
|
||||
}
|
||||
|
||||
private static bool TryParseVersion(string str, out Version version)
|
||||
{
|
||||
if (str.EndsWith(".*"))
|
||||
{
|
||||
str = str.Substring(0, str.Length - 1);
|
||||
int count = str.Split('.').Length;
|
||||
// NOTE this is the published algorithm for generating automatic build and revision numbers
|
||||
// (see AssemblyVersionAttribute constructor docs), but it turns out that the revision
|
||||
// number is off an hour (on my system)...
|
||||
DateTime now = DateTime.Now;
|
||||
int seconds = (int)(now.TimeOfDay.TotalSeconds / 2);
|
||||
int days = (int)(now - new DateTime(2000, 1, 1)).TotalDays;
|
||||
if (count == 3)
|
||||
{
|
||||
str += days + "." + seconds;
|
||||
}
|
||||
else if (count == 4)
|
||||
{
|
||||
str += seconds;
|
||||
}
|
||||
else
|
||||
{
|
||||
version = null;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
try
|
||||
{
|
||||
version = new Version(str);
|
||||
return version.Major <= 65535 && version.Minor <= 65535 && version.Build <= 65535 && version.Revision <= 65535;
|
||||
}
|
||||
catch (ArgumentException) { }
|
||||
catch (FormatException) { }
|
||||
catch (OverflowException) { }
|
||||
version = null;
|
||||
return false;
|
||||
}
|
||||
|
||||
private static bool SetStrongNameKeyPair(ref StrongNameKeyPair strongNameKeyPair, string fileNameOrKeyContainer, bool file)
|
||||
{
|
||||
try
|
||||
|
|
|
@ -49,7 +49,6 @@ namespace IKVM.Internal
|
|||
private string assemblyName;
|
||||
private string assemblyFile;
|
||||
private string assemblyDir;
|
||||
private string version;
|
||||
private bool targetIsModule;
|
||||
private AssemblyBuilder assemblyBuilder;
|
||||
private IKVM.Internal.MapXml.Attribute[] assemblyAttributes;
|
||||
|
@ -73,7 +72,7 @@ namespace IKVM.Internal
|
|||
private List<ClassLoaderWrapper> internalsVisibleTo = new List<ClassLoaderWrapper>();
|
||||
private List<TypeWrapper> dynamicallyImportedTypes = new List<TypeWrapper>();
|
||||
|
||||
internal CompilerClassLoader(AssemblyClassLoader[] referencedAssemblies, CompilerOptions options, string path, string version, bool targetIsModule, string assemblyName, Dictionary<string, byte[]> classes)
|
||||
internal CompilerClassLoader(AssemblyClassLoader[] referencedAssemblies, CompilerOptions options, string path, bool targetIsModule, string assemblyName, Dictionary<string, byte[]> classes)
|
||||
: base(options.codegenoptions, null)
|
||||
{
|
||||
this.referencedAssemblies = referencedAssemblies;
|
||||
|
@ -84,7 +83,6 @@ namespace IKVM.Internal
|
|||
this.assemblyFile = assemblyPath.Name;
|
||||
this.assemblyDir = assemblyPath.DirectoryName;
|
||||
this.targetIsModule = targetIsModule;
|
||||
this.version = version;
|
||||
Tracer.Info(Tracer.Compiler, "Instantiate CompilerClassLoader for {0}", assemblyName);
|
||||
}
|
||||
|
||||
|
@ -142,7 +140,7 @@ namespace IKVM.Internal
|
|||
AssemblyName name = new AssemblyName();
|
||||
name.Name = assemblyName;
|
||||
name.KeyPair = options.key;
|
||||
name.Version = new Version(version);
|
||||
name.Version = options.version;
|
||||
assemblyBuilder =
|
||||
StaticCompiler.Universe
|
||||
.DefineDynamicAssembly(name, AssemblyBuilderAccess.ReflectionOnly, assemblyDir);
|
||||
|
@ -2703,7 +2701,7 @@ namespace IKVM.Internal
|
|||
{
|
||||
referencedAssemblies[i] = AssemblyClassLoader.FromAssembly(references[i]);
|
||||
}
|
||||
loader = new CompilerClassLoader(referencedAssemblies, options, options.path, options.version, options.targetIsModule, options.assembly, h);
|
||||
loader = new CompilerClassLoader(referencedAssemblies, options, options.path, options.targetIsModule, options.assembly, h);
|
||||
loader.baseClasses = baseClasses;
|
||||
loader.assemblyAnnotations = assemblyAnnotations;
|
||||
loader.classesToCompile = new List<string>(h.Keys);
|
||||
|
@ -3082,7 +3080,7 @@ namespace IKVM.Internal
|
|||
{
|
||||
internal string path;
|
||||
internal StrongNameKeyPair key;
|
||||
internal string version;
|
||||
internal Version version;
|
||||
internal string fileversion;
|
||||
internal bool targetIsModule;
|
||||
internal string assembly;
|
||||
|
|
Загрузка…
Ссылка в новой задаче