#!/bin/bash # truncated_input_test.sh - Don Yang (uguu.org) # # 2013-06-05 function die() { echo "$1" exit 1 } if [ $# -ne 2 ]; then die "$0 " fi INPUT_BINARY=$1 TEST_PROG=$2 # Get maximum size of invalid input. Assuming input contains just # enough bytes to make a valid header, one byte shorter would make the # header invalid, hence the subtract one here. SIZE_LIMIT=$(perl -e "print ((-s '$INPUT_BINARY') - 1)") # Feed incomplete headers of varying sizes to test program. We should # always get "0 0" in the output. for i in $(seq $SIZE_LIMIT); do ( head -c $i $INPUT_BINARY | ./$TEST_PROG | grep -q "^0 0$" ) \ || die "Failed at size $i" done # Success exit 0