1#!/bin/ksh -p
2#
3# CDDL HEADER START
4#
5# This file and its contents are supplied under the terms of the
6# Common Development and Distribution License ("CDDL"), version 1.0.
7# You may only use this file in accordance with the terms of version
8# 1.0 of the CDDL.
9#
10# A full copy of the text of the CDDL should have accompanied this
11# source.  A copy of the CDDL is also available via the Internet at
12# http://www.illumos.org/license/CDDL.
13#
14# CDDL HEADER END
15#
16# Copyright (c) 2020 Lawrence Livermore National Security, LLC.
17
18. $STF_SUITE/include/libtest.shlib
19
20#
21# Description:
22# A badly formed object range parameter passed to zdb -dd should
23# return an error.
24#
25# Strategy:
26# 1. Create a pool
27# 2. Run zdb -dd with assorted invalid object range arguments and
28#    confirm it fails as expected
29# 3. Run zdb -dd with an invalid object identifier and
30#    confirm it fails as expected
31
32function cleanup
33{
34	datasetexists $TESTPOOL && destroy_pool $TESTPOOL
35}
36
37log_assert "Execute zdb using invalid object range parameters."
38log_onexit cleanup
39verify_runnable "both"
40verify_disk_count "$DISKS" 2
41default_mirror_setup_noexit $DISKS
42
43sync_all_pools
44
45set -A bad_flags a b c   e   g h i j k l   n o p q r s t u v w x y   \
46                   B C D E F G H I J K L M N O P Q R S T U V W X Y Z \
47                 0 1 2 3 4 5 6 7 8 9 _ - + % . , :
48
49typeset -i i=0
50while [[ $i -lt ${#bad_flags[*]} ]]; do
51	log_mustnot zdb -dd $TESTPOOL 0:1:${bad_flags[i]}
52	log_mustnot zdb -dd $TESTPOOL 0:1:A-${bad_flags[i]}
53	((i = i + 1))
54done
55
56set -A bad_ranges ":" "::" ":::" ":0" "0:" "0:1:" "0:1::" "0::f" "0a:1" \
57    "a0:1" "a:1" "0:a" "0:1a" "0:a1" "a:b0" "a:0b" "0:1:A-" "1:0" \
58    "0:1:f:f" "0:1:f:"
59
60i=0
61while [[ $i -lt ${#bad_ranges[*]} ]]; do
62	log_mustnot zdb -dd $TESTPOOL ${bad_ranges[i]}
63	((i = i + 1))
64done
65
66# Specifying a non-existent object identifier returns an error
67obj_id_highest=$(zdb -P -dd $TESTPOOL/$TESTFS 2>/dev/null |
68    grep -E "^ +-?([0-9]+ +){7}" | sort -n | awk 'END {print $1}')
69obj_id_invalid=$(( $obj_id_highest + 1 ))
70log_mustnot zdb -dd $TESTPOOL/$TESTFS $obj_id_invalid
71
72log_pass "Badly formed zdb object range parameters fail as expected."
73