Skip to content

scripts/diffcheck.sh: Use secure temp files and git archive for better safety #1924

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 17 additions & 5 deletions scripts/diffcheck.sh
Original file line number Diff line number Diff line change
@@ -1,10 +1,22 @@
#!/bin/bash

scripts/buildtable.pl >/tmp/table.mediawiki 2> /dev/null
diff README.mediawiki /tmp/table.mediawiki | grep '^[<>] |' >/tmp/after.diff || true
if git checkout HEAD^ && scripts/buildtable.pl >/tmp/table.mediawiki 2>/dev/null; then
diff README.mediawiki /tmp/table.mediawiki | grep '^[<>] |' >/tmp/before.diff || true
newdiff=$(diff -s /tmp/before.diff /tmp/after.diff -u | grep '^+')
# Create secure temporary directories and ensure cleanup
tmp_dir="$(mktemp -d)"; prev_dir="$(mktemp -d)"; trap 'rm -rf "$tmp_dir" "$prev_dir"' EXIT

# Paths for current commit artifacts
table_file="$tmp_dir/table.mediawiki"
after_diff="$tmp_dir/after.diff"
before_diff="$tmp_dir/before.diff"
table_prev_file="$tmp_dir/table_prev.mediawiki"

# Build table from current working tree and compute diff
scripts/buildtable.pl >"$table_file" 2>/dev/null
diff README.mediawiki "$table_file" | grep '^[<>] |' >"$after_diff" || true

# Build table from previous commit without altering the working tree
if git archive --format=tar HEAD^ | tar -x -C "$prev_dir" && perl "$prev_dir/scripts/buildtable.pl" >"$table_prev_file" 2>/dev/null; then
diff "$prev_dir/README.mediawiki" "$table_prev_file" | grep '^[<>] |' >"$before_diff" || true
newdiff=$(diff -s "$before_diff" "$after_diff" -u | grep '^+')
if [ -n "$newdiff" ]; then
echo "$newdiff"
exit 1
Expand Down