Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't consider .mdiff or .sdiff files in discoverTestData #637

Merged
merged 2 commits into from
Nov 18, 2024

Conversation

egibs
Copy link
Member

@egibs egibs commented Nov 17, 2024

Addresses the bug seen here: https://github.com/chainguard-dev/malcontent/pull/636/files#r1845470148

I was considering .mdiff and .sdiff files as part of the code that replaced this Bash:

for f in $(find "${test_data}" -name "*.simple"); do
	prog=$(echo $f | sed -e s#"${test_data}/"## -e s#\.simple\$##)
	if [[ -s "${prog}" ]]; then
		addq ${malcontent} --format=simple --min-file-risk=1 --min-risk=1 --ignore-tags=harmless -o "${f}" analyze "${prog}"
	else
		"*** ${prog} sample is empty or does not exist"
		exit 1
	fi
done
for f in $(find "${test_data}" -name "*.md"); do
	prog=$(echo $f | sed -e s#"${test_data}/"## -e s#\.md\$##)
	if [[ -s "${prog}" ]]; then
		addq ${malcontent} --format=markdown --min-file-risk=1 --min-risk=1 --ignore-tags=harmless -o "${f}" analyze "${prog}"
	else
		"*** ${prog} sample is empty or does not exist"
		exit 1
	fi
done
for f in $(find "${test_data}" -name "*.json"); do
	prog=$(echo $f | sed -e s#"${test_data}/"## -e s#\.json\$##)
	if [[ -s "${prog}" ]]; then
		addq ${malcontent} --format=json --min-file-risk=1 --min-risk=1 -o "${f}" analyze "${prog}"
	else
		"*** ${prog} sample is empty or does not exist"
		exit 1
	fi
done

.mdiff and .sdiff files should only be handled by the diffRefresh function and having them in two places caused drift/clobbering in cases where the filenames without extensions were the same (e.g., ls.json being scanned instead of the ls binary).

With this code, I ran about 10 refresh loops and the problematic ls.mdiff file retained its header consistently:

## Changed: macOS/clean/ls [🟡 MEDIUM → 🔵 LOW]

whereas the original code would flip back and forth between this and ## Changed: macOS/clean/ls.json arbitrarily (depending on which Task was executed last).

Signed-off-by: egibs <20933572+egibs@users.noreply.github.com>
@egibs egibs requested a review from tstromberg November 17, 2024 14:31
@egibs egibs enabled auto-merge (squash) November 17, 2024 14:36
@egibs egibs merged commit 0209157 into chainguard-dev:main Nov 18, 2024
8 checks passed
tstromberg pushed a commit to tstromberg/malcontent that referenced this pull request Nov 18, 2024
…-dev#637)

Signed-off-by: egibs <20933572+egibs@users.noreply.github.com>
tstromberg added a commit that referenced this pull request Nov 18, 2024
* Teach malcontent about more Python maliciousness

* refresh testdata

* rule tuning

* Update third-party rules as of 2024-11-18 (#641)

Co-authored-by: Update third-party rules <41898282+github-actions[bot]@users.noreply.github.com>

* Don't consider .mdiff or .sdiff files in discoverTestData (#637)

Signed-off-by: egibs <20933572+egibs@users.noreply.github.com>

* update sample commit

* update testdata

* rule tuning

---------

Signed-off-by: egibs <20933572+egibs@users.noreply.github.com>
Co-authored-by: octo-sts[bot] <157150467+octo-sts[bot]@users.noreply.github.com>
Co-authored-by: Update third-party rules <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Evan Gibler <20933572+egibs@users.noreply.github.com>
@egibs egibs deleted the refresh-tweaks branch November 18, 2024 16:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants