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