124f3078aSKevin Wolf#!/bin/bash 224f3078aSKevin Wolf# 324f3078aSKevin Wolf# bochs format input validation tests 424f3078aSKevin Wolf# 524f3078aSKevin Wolf# Copyright (C) 2013 Red Hat, Inc. 624f3078aSKevin Wolf# 724f3078aSKevin Wolf# This program is free software; you can redistribute it and/or modify 824f3078aSKevin Wolf# it under the terms of the GNU General Public License as published by 924f3078aSKevin Wolf# the Free Software Foundation; either version 2 of the License, or 1024f3078aSKevin Wolf# (at your option) any later version. 1124f3078aSKevin Wolf# 1224f3078aSKevin Wolf# This program is distributed in the hope that it will be useful, 1324f3078aSKevin Wolf# but WITHOUT ANY WARRANTY; without even the implied warranty of 1424f3078aSKevin Wolf# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 1524f3078aSKevin Wolf# GNU General Public License for more details. 1624f3078aSKevin Wolf# 1724f3078aSKevin Wolf# You should have received a copy of the GNU General Public License 1824f3078aSKevin Wolf# along with this program. If not, see <http://www.gnu.org/licenses/>. 1924f3078aSKevin Wolf# 2024f3078aSKevin Wolf 2124f3078aSKevin Wolf# creator 2224f3078aSKevin Wolfowner=kwolf@redhat.com 2324f3078aSKevin Wolf 2424f3078aSKevin Wolfseq=`basename $0` 2524f3078aSKevin Wolfecho "QA output created by $seq" 2624f3078aSKevin Wolf 2724f3078aSKevin Wolfhere=`pwd` 2824f3078aSKevin Wolftmp=/tmp/$$ 2924f3078aSKevin Wolfstatus=1 # failure is the default! 3024f3078aSKevin Wolf 3124f3078aSKevin Wolf_cleanup() 3224f3078aSKevin Wolf{ 3324f3078aSKevin Wolf _cleanup_test_img 3424f3078aSKevin Wolf} 3524f3078aSKevin Wolftrap "_cleanup; exit \$status" 0 1 2 3 15 3624f3078aSKevin Wolf 3724f3078aSKevin Wolf# get standard environment, filters and checks 3824f3078aSKevin Wolf. ./common.rc 3924f3078aSKevin Wolf. ./common.filter 4024f3078aSKevin Wolf 4124f3078aSKevin Wolf_supported_fmt bochs 42*c5f7c0afSPeter Lieven_supported_proto file 4324f3078aSKevin Wolf_supported_os Linux 4424f3078aSKevin Wolf 45246f6583SKevin Wolfcatalog_size_offset=$((0x48)) 468e53abbcSKevin Wolfextent_size_offset=$((0x50)) 47e3737b82SKevin Wolfdisk_size_offset=$((0x58)) 48246f6583SKevin Wolf 4924f3078aSKevin Wolfecho 5024f3078aSKevin Wolfecho "== Read from a valid image ==" 5124f3078aSKevin Wolf_use_sample_img empty.bochs.bz2 5224f3078aSKevin Wolf{ $QEMU_IO -c "read 0 512" $TEST_IMG; } 2>&1 | _filter_qemu_io | _filter_testdir 5324f3078aSKevin Wolf 54246f6583SKevin Wolfecho 55246f6583SKevin Wolfecho "== Negative catalog size ==" 56246f6583SKevin Wolf_use_sample_img empty.bochs.bz2 57246f6583SKevin Wolfpoke_file "$TEST_IMG" "$catalog_size_offset" "\xff\xff\xff\xff" 58246f6583SKevin Wolf{ $QEMU_IO -c "read 0 512" $TEST_IMG; } 2>&1 | _filter_qemu_io | _filter_testdir 59246f6583SKevin Wolf 60e3737b82SKevin Wolfecho 61e3737b82SKevin Wolfecho "== Overflow for catalog size * sizeof(uint32_t) ==" 62e3737b82SKevin Wolf_use_sample_img empty.bochs.bz2 63e3737b82SKevin Wolfpoke_file "$TEST_IMG" "$catalog_size_offset" "\x00\x00\x00\x40" 64e3737b82SKevin Wolf{ $QEMU_IO -c "read 0 512" $TEST_IMG; } 2>&1 | _filter_qemu_io | _filter_testdir 65e3737b82SKevin Wolf 66e3737b82SKevin Wolfecho 67e3737b82SKevin Wolfecho "== Too small catalog bitmap for image size ==" 68e3737b82SKevin Wolf_use_sample_img empty.bochs.bz2 69e3737b82SKevin Wolfpoke_file "$TEST_IMG" "$disk_size_offset" "\x00\xc0\x0f\x00\x00\x00\x00\x7f" 70e3737b82SKevin Wolf{ $QEMU_IO -c "read 2T 4k" $TEST_IMG; } 2>&1 | _filter_qemu_io | _filter_testdir 71e3737b82SKevin Wolf 72715c3f60SKevin Wolf_use_sample_img empty.bochs.bz2 73715c3f60SKevin Wolfpoke_file "$TEST_IMG" "$catalog_size_offset" "\x10\x00\x00\x00" 74715c3f60SKevin Wolf{ $QEMU_IO -c "read 0xfbe00 512" $TEST_IMG; } 2>&1 | _filter_qemu_io | _filter_testdir 75715c3f60SKevin Wolf 768e53abbcSKevin Wolfecho 778e53abbcSKevin Wolfecho "== Negative extent size ==" 788e53abbcSKevin Wolf_use_sample_img empty.bochs.bz2 79715c3f60SKevin Wolfpoke_file "$TEST_IMG" "$extent_size_offset" "\x00\x00\x00\x80" 808e53abbcSKevin Wolf{ $QEMU_IO -c "read 768k 512" $TEST_IMG; } 2>&1 | _filter_qemu_io | _filter_testdir 818e53abbcSKevin Wolf 828e53abbcSKevin Wolfecho 838e53abbcSKevin Wolfecho "== Zero extent size ==" 848e53abbcSKevin Wolf_use_sample_img empty.bochs.bz2 858e53abbcSKevin Wolfpoke_file "$TEST_IMG" "$extent_size_offset" "\x00\x00\x00\x00" 868e53abbcSKevin Wolf{ $QEMU_IO -c "read 0 512" $TEST_IMG; } 2>&1 | _filter_qemu_io | _filter_testdir 878e53abbcSKevin Wolf 8824f3078aSKevin Wolf# success, all done 8924f3078aSKevin Wolfecho "*** done" 9024f3078aSKevin Wolfrm -f $seq.full 9124f3078aSKevin Wolfstatus=0 92