From 193ee733ab915c205bc6711521116fcec1c72ef7 Mon Sep 17 00:00:00 2001 From: MascaraSnake Date: Fri, 22 Jan 2016 23:50:23 +0100 Subject: [PATCH] Merged in GZDB r2463. --- Source/Core/GZBuilder/GZDoom/GldefsParser.cs | 7 +++-- .../GZBuilder/GZDoom/ModeldefStructure.cs | 26 ++++++++++------- Source/Core/ZDoom/DecorateParser.cs | 7 +++-- Source/Core/ZDoom/ZDTextParser.cs | 28 +++++++++++++++++-- 4 files changed, 52 insertions(+), 16 deletions(-) diff --git a/Source/Core/GZBuilder/GZDoom/GldefsParser.cs b/Source/Core/GZBuilder/GZDoom/GldefsParser.cs index 940918e..fdc2f9b 100644 --- a/Source/Core/GZBuilder/GZDoom/GldefsParser.cs +++ b/Source/Core/GZBuilder/GZDoom/GldefsParser.cs @@ -660,8 +660,11 @@ namespace CodeImp.DoomBuilder.GZBuilder.GZDoom return false; } - // Absolute paths are not supported... - if(Path.IsPathRooted(includelump)) + // Check invalid path chars + if (!CheckInvalidPathChars(token)) return false; + + // Absolute paths are not supported... + if (Path.IsPathRooted(includelump)) { ReportError("Absolute include paths are not supported by ZDoom"); return false; diff --git a/Source/Core/GZBuilder/GZDoom/ModeldefStructure.cs b/Source/Core/GZBuilder/GZDoom/ModeldefStructure.cs index 20da229..dcd0ac1 100644 --- a/Source/Core/GZBuilder/GZDoom/ModeldefStructure.cs +++ b/Source/Core/GZBuilder/GZDoom/ModeldefStructure.cs @@ -96,17 +96,20 @@ namespace CodeImp.DoomBuilder.GZBuilder.GZDoom { parser.ReportError("Expected model name"); return false; - } + } - //check extension - string fileExt = Path.GetExtension(token); - if(string.IsNullOrEmpty(fileExt)) + //check invalid path chars + if (!parser.CheckInvalidPathChars(token)) return false; + + //check extension + string modelext = Path.GetExtension(token); + if(string.IsNullOrEmpty(modelext)) { parser.ReportError("Model '" + token + "' won't be loaded. Models without extension are not supported by GZDoom"); return false; } - if(fileExt != ".md3" && fileExt != ".md2") + if(modelext != ".md3" && modelext != ".md2") { parser.ReportError("Model '" + token + "' won't be loaded. Only MD2 and MD3 models are supported"); return false; @@ -147,13 +150,16 @@ namespace CodeImp.DoomBuilder.GZBuilder.GZDoom { parser.ReportError("Skin path required"); return false; - } + } - //check extension - string ext = Path.GetExtension(token); - if(Array.IndexOf(ModelData.SUPPORTED_TEXTURE_EXTENSIONS, ext) == -1) + //check invalid path chars + if (!parser.CheckInvalidPathChars(token)) return false; + + //check extension + string texext = Path.GetExtension(token); + if(Array.IndexOf(ModelData.SUPPORTED_TEXTURE_EXTENSIONS, texext) == -1) { - parser.ReportError("Image format '" + ext + "' is not supported"); + parser.ReportError("Image format '" + texext + "' is not supported"); return false; } diff --git a/Source/Core/ZDoom/DecorateParser.cs b/Source/Core/ZDoom/DecorateParser.cs index 040fb4e..6844e34 100644 --- a/Source/Core/ZDoom/DecorateParser.cs +++ b/Source/Core/ZDoom/DecorateParser.cs @@ -168,8 +168,11 @@ namespace CodeImp.DoomBuilder.ZDoom return false; } - //mxd. Absolute paths are not supported... - if(Path.IsPathRooted(filename)) + //mxd. Check invalid path chars + if (!CheckInvalidPathChars(filename)) return false; + + //mxd. Absolute paths are not supported... + if (Path.IsPathRooted(filename)) { ReportError("Absolute include paths are not supported by ZDoom"); return false; diff --git a/Source/Core/ZDoom/ZDTextParser.cs b/Source/Core/ZDoom/ZDTextParser.cs index fa8e7fc..8e9f65f 100644 --- a/Source/Core/ZDoom/ZDTextParser.cs +++ b/Source/Core/ZDoom/ZDTextParser.cs @@ -594,8 +594,32 @@ namespace CodeImp.DoomBuilder.ZDoom return result; } - //mxd. Language type - protected abstract string GetLanguageType(); + //mxd. This replicates System.IO.Path.CheckInvalidPathChars() internal function + public bool CheckInvalidPathChars(string path) + { + foreach (char c in path) + { + int num = c; + switch (num) + { + case 34: + case 60: + case 62: + case 124: + ReportError("unsupported character \"" + c + "\" in path \"" + path + "\"."); + return false; + + default: + if (num >= 32) continue; + goto case 34; + } + } + + return true; + } + + //mxd. Language type + protected abstract string GetLanguageType(); #endregion }