Skip to content

Commit

Permalink
Minor changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Anilm3 committed Jul 10, 2024
1 parent 3c3f8e9 commit 34b5a44
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
14 changes: 9 additions & 5 deletions src/condition/shi_detector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,15 @@ namespace ddwaf {

namespace {

using shi_result = std::optional<std::pair<std::string, std::vector<std::string>>>;

shi_result shi_string_impl(std::string_view resource, std::vector<shell_token> &resource_tokens,
const ddwaf_object &params, const exclusion::object_set_ref &objects_excluded,
const object_limits &limits, ddwaf::timer &deadline)
struct shi_result {
std::string value;
std::vector<std::string> key_path;
};

std::optional<shi_result> shi_string_impl(std::string_view resource,
std::vector<shell_token> &resource_tokens, const ddwaf_object &params,
const exclusion::object_set_ref &objects_excluded, const object_limits &limits,
ddwaf::timer &deadline)
{
object::kv_iterator it(&params, {}, objects_excluded, limits);
for (; it; ++it) {
Expand Down
6 changes: 6 additions & 0 deletions src/tokenizer/shell.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,21 @@ namespace {
re2::RE2 redirection_regex(
R"((&>>?|(?:[0-9]*>(?:\||>|&[0-9]*-?)?)|(?:[0-9]*<(?:<(?:-|<)?|&[0-9]*-?|>)?)))");

// Valid characters in a variable name
bool is_var_char(char c) { return ddwaf::isalnum(c) || c == '_'; }

// This functions returns true for any character which could potentially belong to a field and has
// no secondary meaning, for example, the { character could be part of a field, but it might also
// have a secondary meaning (command grouping), hence it allows us to attempt to match a potentially
// different token if applicable.
bool is_field_char(char c)
{
return c != '`' && c != '$' && c != '{' && c != '}' && c != '[' && c != ']' && c != '(' &&
c != ')' && c != '\'' && c != '"' && c != '#' && c != '=' && c != '|' && c != '<' &&
c != '>' && c != ';' && c != '&' && c != '\n' && c != '\t' && c != ' ';
}

// Characters used to represent a space
bool is_space_char(char c) { return c == ' ' || c == '\t'; }

void find_executables_and_strip_whitespaces(std::vector<shell_token> &tokens)
Expand Down

0 comments on commit 34b5a44

Please sign in to comment.