MCPcopy Create free account
hub / github.com/DeusData/codebase-memory-mcp / validate_search_path_arg

Function validate_search_path_arg

src/mcp/mcp.c:5043–5068  ·  view source on GitHub ↗

Validate shell-safe arguments for search. */ Search/grep paths and globs are ALWAYS single-quoted (POSIX sh) or * double-/single-quoted (Windows cmd/PowerShell) on the command line, which * neutralises '&' — a very common character in real paths (R&D, "Foo & Bar", * OneDrive). Accept '&' here while still rejecting every metacharacter that * could break out of the quoting (#272). */

Source from the content-addressed store, hash-verified

5041 * OneDrive). Accept '&' here while still rejecting every metacharacter that
5042 * could break out of the quoting (#272). */
5043static bool validate_search_path_arg(const char *s) {
5044 if (!s) {
5045 return false;
5046 }
5047 for (const char *p = s; *p; p++) {
5048 switch (*p) {
5049 case '\'':
5050 case '"':
5051 case ';':
5052 case '|':
5053 case '$':
5054 case '`':
5055 case '<':
5056 case '>':
5057 case '\n':
5058 case '\r':
5059#ifndef _WIN32
5060 case '\\':
5061#endif
5062 return false;
5063 default:
5064 break;
5065 }
5066 }
5067 return true;
5068}
5069
5070static bool validate_search_args(const char *root_path, const char *file_pattern) {
5071 if (!validate_search_path_arg(root_path)) {

Callers 2

validate_search_argsFunction · 0.85
handle_detect_changesFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected