Skip to content

Commit 5c69adf

Browse files
committed
Don't allow "info args n" to use n outside the valid range
Max value of n is one less than the current stack depth.
1 parent f5e83cc commit 5c69adf

File tree

3 files changed

+9
-12
lines changed

3 files changed

+9
-12
lines changed

command/info_sub/args.sh

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ See also:
4444

4545
_Dbg_do_info_args() {
4646

47-
typeset -r frame_start=${1:-0}
47+
typeset -r frame_start="${1:-0}"
4848

4949
eval "$_Dbg_seteglob"
5050
if [[ $frame_start != $_Dbg_int_pat ]] ; then
@@ -53,22 +53,15 @@ _Dbg_do_info_args() {
5353
return 1
5454
fi
5555

56-
# source /usr/local/share/bashdb/bashdb-trace
57-
# _Dbg_debugger
58-
59-
typeset -i i=$frame_start
60-
61-
(( i >= _Dbg_stack_size )) && return 1
56+
typeset -i i="$frame_start"
57+
(( i >= _Dbg_stack_size - 1 )) && return 1
6258

6359
# Figure out which index in BASH_ARGV is position "i" (the place where
6460
# we start our stack trace from). variable "r" will be that place.
6561

6662
typeset -i adjusted_pos
67-
adjusted_pos=$(_Dbg_frame_adjusted_pos $frame_start)
63+
adjusted_pos=$(_Dbg_frame_adjusted_pos $i)
6864
typeset -i arg_count=${BASH_ARGC[$adjusted_pos]}
69-
# echo "arg count is " $arg_count
70-
# echo "adjusted_pos is" $adjusted_pos
71-
# typeset -p BASH_ARGC
7265

7366
# Print out parameter list.
7467
if (( 0 != ${#BASH_ARGC[@]} )) ; then

test/data/info-args.cmd

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,6 @@ info args
55
c hanoi
66
info args
77
info functions ^ha
8+
info args 3
9+
info args 100
810
quit

test/data/info-args.right

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,7 @@ $3 = b
1919
$4 = c
2020
+info functions ^ha
2121
hanoi
22-
+quit
22+
+info args 3
23+
+info args 100
24+
+quit
2325
bashdb: That's all, folks...

0 commit comments

Comments
 (0)