Skip to content

Commit

Permalink
chore: added pre-commit hook for sourcecode sample files execution pe…
Browse files Browse the repository at this point in the history
…rmissions
  • Loading branch information
art1f1c3R committed Feb 5, 2025
1 parent a9d736d commit 8bc6532
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
12 changes: 12 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,18 @@ repos:
always_run: true
pass_filenames: false

# Checks that tests/malware_analyzer/pypi/resources/sourcecode_samples files do not have executable permissions
# This is another measure to make sure the files can't be accidentally executed
- repo: local
hooks:
- id: sourcecode-sample-permissions
name: Sourcecode sample executable permissions checker
entry: scripts/dev_scripts/samples_permissions_checker.sh
language: system
always_run: true
pass_filenames: false


# A linter for Golang
- repo: https://github.com/golangci/golangci-lint
rev: v1.61.0
Expand Down
20 changes: 20 additions & 0 deletions scripts/dev_scripts/samples_permissions_checker.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/usr/bin/env bash

# Copyright (c) 2022 - 2025, Oracle and/or its affiliates. All rights reserved.
# Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl/.

#
# Checks if the files in tests/malware_analyzer/pypi/resources/sourcecode_samples have executable permissions,
# failing if any do.
#

MACARON_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && cd ../.. && pwd)"
SAMPLES_PATH="${MACARON_DIR}/tests/malware_analyzer/pypi/resources/sourcecode_samples"

# any files have any of the executable bits set
executables=$(find "$SAMPLES_PATH" -type f -perm -u+x -o -type f -perm -g+x -o -type f -perm -o+x)
if [ -n "$executables" ]; then
echo "The following files should not have any executable permissions:"
echo "$executables"
exit 1
fi

0 comments on commit 8bc6532

Please sign in to comment.