diff --git a/src/transaction.cc b/src/transaction.cc index 92a7c36f..ccf08652 100644 --- a/src/transaction.cc +++ b/src/transaction.cc @@ -406,9 +406,9 @@ int Transaction::processURI(const char *uri, const char *method, m_collections.store("REQUEST_FILENAME", path_info); size_t offset = path_info.find_last_of("/\\"); - if (offset != std::string::npos) { - std::string basename = std::string(path_info, offset, - path_info.length() - offset); + if (offset != std::string::npos && path_info.length() > offset + 1) { + std::string basename = std::string(path_info, offset + 1, + path_info.length() - (offset + 1)); m_collections.store("REQUEST_BASENAME", basename); } m_collections.store("REQUEST_METHOD", method); diff --git a/test/test-cases/regression/variable-REQUEST_BASENAME.json b/test/test-cases/regression/variable-REQUEST_BASENAME.json index 5a703af9..27cbbb64 100644 --- a/test/test-cases/regression/variable-REQUEST_BASENAME.json +++ b/test/test-cases/regression/variable-REQUEST_BASENAME.json @@ -33,7 +33,7 @@ ] }, "expected":{ - "debug_log":"Target value: \"/login.php\" \\(Variable: REQUEST_BASENAME\\)" + "debug_log":"Target value: \"login.php\" \\(Variable: REQUEST_BASENAME\\)" }, "rules":[ "SecRuleEngine On",