From 26281777469963e05a603353ad9ffcf4d0bfd1ee Mon Sep 17 00:00:00 2001 From: ZhuangYumin Date: Thu, 14 Dec 2023 04:18:29 +0000 Subject: [PATCH] fix: fix su's lexer --- backend/src/engine.cpp | 2 ++ backend/src/lexer.cpp | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/backend/src/engine.cpp b/backend/src/engine.cpp index cf4a5da..f5ada9c 100644 --- a/backend/src/engine.cpp +++ b/backend/src/engine.cpp @@ -115,8 +115,10 @@ std::vector BookStoreEngineClass::ExecuteSu( std::string user_id, password; if (!CommandSuLexer(cmd, user_id, password)) return std::vector({"Invalid"}); + // debugPrint("su", user_id, " ", password); if (login_stack.size() > 0 && user_data_base.GetPrevilege(login_stack.top().first) == 7) { + // debugPrint("has root previlege"); if (user_data_base.GetPrevilege(user_id) == -1) return std::vector({"Invalid"}); login_stack.push(std::make_pair(user_id, "")); diff --git a/backend/src/lexer.cpp b/backend/src/lexer.cpp index a73d2d2..cab8ca1 100644 --- a/backend/src/lexer.cpp +++ b/backend/src/lexer.cpp @@ -18,7 +18,7 @@ bool CommandSuLexer(const std::string &command, std::string &user_id, std::string &password) { static std::basic_regex main_pattern( - R"(^ *su +(?:[0-9a-zA-Z_]{1,30}) +(?:[0-9a-zA-Z_]{1,30})? *$)", + R"(^ *su +(?:[0-9a-zA-Z_]{1,30})(?: +[0-9a-zA-Z_]{1,30})? *$)", std::regex_constants::optimize); if (std::regex_match(command, main_pattern)) { std::stringstream ss(command);