Skip to content

Commit

Permalink
Merge pull request #242 from avast/fix-json-permissions
Browse files Browse the repository at this point in the history
fix: Open json modules in read only mode
  • Loading branch information
MatejKastak committed Mar 27, 2023
2 parents 7c7931a + b995885 commit 2779af7
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/utils/json.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ namespace yaramod {

nlohmann::json readJsonFile(const std::string& filePath)
{
std::ifstream input{filePath, std::ios::out};
std::ifstream input{filePath};
if (!input.is_open())
throw YaramodError("Could not open '" + filePath);
std::stringstream buffer;
Expand Down
37 changes: 37 additions & 0 deletions tests/python/test_modules.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import yaramod

def test_modules_that_are_readonly(tmp_path):
modules_directory = tmp_path
my_cuckoo_module = modules_directory / "my_cuckoo.json"
my_cuckoo_module.write_text('''{
"kind": "struct",
"name": "cuckoo",
"attributes": [
{
"kind": "function",
"name": "my_func",
"return_type": "i",
"overloads": [
{
"arguments": [
{
"type": "r",
"name": "data"
}
],
"documentation": "Test"
}
]
}
]
}
''')
my_cuckoo_module.chmod(0o444)
ymod = yaramod.Yaramod(modules_directory=str(modules_directory))
yfile = ymod.parse_string(r'''import "cuckoo"
rule test {
condition:
cuckoo.my_func(/.*/)
}
''')
assert yfile is not None

0 comments on commit 2779af7

Please sign in to comment.