#!/usr/bin/sh
# PCP QA Test No. 2102
# Verify pmlogmv rejects shell metacharacters in filenames
# and that normal move operations still work (CWE-78 fix)
#
# Copyright (c) 2026 Red Hat.  All Rights Reserved.
#

seq=`basename $0`
echo "QA output created by $seq"

# get standard environment, filters and checks
. ./common.product
. ./common.filter
. ./common.check

_cleanup()
{
    cd $here
    $sudo rm -rf $tmp $tmp.*
}

status=0	# success is the default!
trap "_cleanup; exit \$status" 0 1 2 3 15

_filter()
{
    sed \
	-e "s,$tmp,TMP,g" \
	-e "s/pmlogmv/TOOL/" \
    # end
}

# real QA test starts here

echo "=== normal pmlogmv should succeed ==="
for ext in meta 0 index
do
    [ -f tmparch/foo.$ext ] && cp tmparch/foo.$ext $tmp.src.$ext
done
pmlogmv $tmp.src $tmp.mvdest 2>&1 | _filter
if [ -f $tmp.mvdest.meta ] || [ -f $tmp.mvdest.0 ]; then
    echo "move succeeded"
else
    echo "FAIL: move did not create files"
fi

echo
echo "=== pmlogmv with backtick in destination should be rejected ==="
pmlogmv tmparch/foo "$tmp.bad\`id\`" >$tmp.out 2>&1
_sts=$?
_filter <$tmp.out
echo "exit status: $_sts"

echo
echo "=== pmlogmv with semicolon in destination should be rejected ==="
pmlogmv tmparch/foo "$tmp.bad;id" >$tmp.out 2>&1
_sts=$?
_filter <$tmp.out
echo "exit status: $_sts"

echo
echo "=== pmlogmv with dollar in destination should be rejected ==="
pmlogmv tmparch/foo '$tmp.bad${IFS}' >$tmp.out 2>&1
_sts=$?
_filter <$tmp.out
echo "exit status: $_sts"
