From 269c61ffdb23062fb51f406bb6f511f884ddb12d Mon Sep 17 00:00:00 2001 From: Leonmmcoset Date: Thu, 12 Feb 2026 00:22:12 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B7=AF=E5=BE=84bug=202+=E9=9D=9E=E6=B3=95?= =?UTF-8?q?=E5=AD=97=E7=AC=A6=E6=A3=80=E6=B5=8B+Lua=20os.osversion()?= =?UTF-8?q?=E5=87=BD=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- GitCommit.txt | 2 +- System/FileSystem.cs | 51 ++++++++++++++++++++++++++++++ System/UserSystem.cs | 24 ++++++++++++++ interpreter/UniLua/LuaOsLib.cs | 8 +++++ shell/Commands/User/UserCommand.cs | 19 +++++++++++ 5 files changed, 103 insertions(+), 1 deletion(-) diff --git a/GitCommit.txt b/GitCommit.txt index 9f42be1..5858063 100644 --- a/GitCommit.txt +++ b/GitCommit.txt @@ -1 +1 @@ -b36e3ba \ No newline at end of file +b80c5b4 \ No newline at end of file diff --git a/System/FileSystem.cs b/System/FileSystem.cs index 0f156c7..6cadc32 100644 --- a/System/FileSystem.cs +++ b/System/FileSystem.cs @@ -14,6 +14,19 @@ namespace CMLeonOS currentDirectory = @"0:\"; } + private static bool ContainsInvalidChars(string input) + { + char[] invalidChars = { '<', '>', ':', '"', '|', '?', '*' }; + foreach (char c in invalidChars) + { + if (input.Contains(c.ToString())) + { + return true; + } + } + return false; + } + public FileSystem(string initialPath) { if (string.IsNullOrEmpty(initialPath)) @@ -67,6 +80,12 @@ namespace CMLeonOS public void MakeDirectory(string path) { + if (ContainsInvalidChars(path)) + { + Console.WriteLine("Error: Directory name contains invalid characters: < > : \" | ?"); + return; + } + string fullPath = GetFullPath(path); try @@ -363,6 +382,28 @@ namespace CMLeonOS return currentDirectory; } + if (path.Length > 255) + { + Console.WriteLine("Error: Path too long (maximum 255 characters)"); + return currentDirectory; + } + + char[] invalidChars = { '<', '>', ':', '"', '|', '?', '*' }; + foreach (char c in invalidChars) + { + if (path.Contains(c.ToString())) + { + Console.WriteLine($"Error: Invalid character in path: '{c}'"); + return currentDirectory; + } + } + + if (path.Contains("//") || path.Contains("\\\\")) + { + Console.WriteLine("Error: Path contains consecutive slashes"); + return currentDirectory; + } + if (path.StartsWith(@"0:\")) { return path; @@ -467,6 +508,16 @@ namespace CMLeonOS string normalizedPath = path; + while (normalizedPath.Contains("//")) + { + normalizedPath = normalizedPath.Replace("//", "/"); + } + + while (normalizedPath.Contains("\\\\")) + { + normalizedPath = normalizedPath.Replace("\\\\", "\\"); + } + if (normalizedPath.StartsWith("/")) { normalizedPath = normalizedPath.Substring(1); diff --git a/System/UserSystem.cs b/System/UserSystem.cs index abd3af7..08c7f31 100644 --- a/System/UserSystem.cs +++ b/System/UserSystem.cs @@ -53,6 +53,19 @@ namespace CMLeonOS return Convert.ToBase64String(sha256.GetHash()); } + private static bool ContainsInvalidChars(string input) + { + char[] invalidChars = { '<', '>', ':', '"', '|', '?', '*', '/', '\\' }; + foreach (char c in invalidChars) + { + if (input.Contains(c.ToString())) + { + return true; + } + } + return false; + } + public UserSystem() { EnsureSysDirectoryExists(); @@ -388,6 +401,17 @@ namespace CMLeonOS username = global::System.Console.ReadLine(); } + while (ContainsInvalidChars(username)) + { + CMLeonOS.UI.TUIHelper.SetColors(global::System.ConsoleColor.Red, global::System.ConsoleColor.Black); + global::System.Console.SetCursorPosition(7, 24); + global::System.Console.Write("Username contains invalid characters: < > : \" | ? / \\ "); + CMLeonOS.UI.TUIHelper.SetColors(global::System.ConsoleColor.White, global::System.ConsoleColor.Black); + global::System.Console.SetCursorPosition(7, 7); + global::System.Console.Write("Username: "); + username = global::System.Console.ReadLine(); + } + CMLeonOS.UI.TUIHelper.SetColors(global::System.ConsoleColor.White, global::System.ConsoleColor.Black); global::System.Console.SetCursorPosition(7, 8); global::System.Console.Write("Password: "); diff --git a/interpreter/UniLua/LuaOsLib.cs b/interpreter/UniLua/LuaOsLib.cs index f2934a5..aa8e12c 100644 --- a/interpreter/UniLua/LuaOsLib.cs +++ b/interpreter/UniLua/LuaOsLib.cs @@ -39,6 +39,7 @@ namespace UniLua new NameFuncPair("base64decrypt", OS_Base64Decrypt), new NameFuncPair("timerstart", OS_TimerStart), new NameFuncPair("timerstop", OS_TimerStop), + new NameFuncPair("osversion", OS_Osversion), new NameFuncPair("tui_drawbox", OS_TUIDrawBox), new NameFuncPair("tui_drawtext", OS_TUIDrawText), new NameFuncPair("tui_setcolor", OS_TUISetColor), @@ -240,6 +241,13 @@ namespace UniLua return 1; } + private static int OS_Osversion(ILuaState lua) + { + string version = CMLeonOS.Version.FullVersion; + lua.PushString(version); + return 1; + } + private static int OS_TUIDrawBox(ILuaState lua) { int x = (int)lua.L_CheckNumber(1); diff --git a/shell/Commands/User/UserCommand.cs b/shell/Commands/User/UserCommand.cs index 2417b35..627456b 100644 --- a/shell/Commands/User/UserCommand.cs +++ b/shell/Commands/User/UserCommand.cs @@ -8,6 +8,19 @@ namespace CMLeonOS.Commands.User { private static CMLeonOS.UserSystem userSystem; + private static bool ContainsInvalidChars(string input) + { + char[] invalidChars = { '<', '>', ':', '"', '|', '?', '*', '/', '\\' }; + foreach (char c in invalidChars) + { + if (input.Contains(c.ToString())) + { + return true; + } + } + return false; + } + public static void SetUserSystem(CMLeonOS.UserSystem system) { userSystem = system; @@ -80,6 +93,12 @@ namespace CMLeonOS.Commands.User string password = parts[3]; bool isAdmin = userType == "admin"; + if (ContainsInvalidChars(username)) + { + showError("Error: Username contains invalid characters: < > : \" | ? / \\"); + return; + } + userSystem.AddUser($"{username} {password}", isAdmin); } else if (subCommand == "delete")