From b42e3cc0d4c118aa6eef399e8762f3f0487f1dfa Mon Sep 17 00:00:00 2001 From: Joachim Ansorg Date: Wed, 9 Oct 2024 15:50:35 +0200 Subject: [PATCH] Don't allow "info args n" to use n outside the valid range (#43) Max value of n is one less than the current stack depth. --- command/info_sub/args.sh | 15 ++++----------- test/data/info-args.cmd | 2 ++ test/data/info-args.right | 4 +++- 3 files changed, 9 insertions(+), 12 deletions(-) diff --git a/command/info_sub/args.sh b/command/info_sub/args.sh index 8be953f1..2f3408b9 100644 --- a/command/info_sub/args.sh +++ b/command/info_sub/args.sh @@ -44,7 +44,7 @@ See also: _Dbg_do_info_args() { - typeset -r frame_start=${1:-0} + typeset -r frame_start="${1:-0}" eval "$_Dbg_seteglob" if [[ $frame_start != $_Dbg_int_pat ]] ; then @@ -53,22 +53,15 @@ _Dbg_do_info_args() { return 1 fi - # source /usr/local/share/bashdb/bashdb-trace - # _Dbg_debugger - - typeset -i i=$frame_start - - (( i >= _Dbg_stack_size )) && return 1 + typeset -i i="$frame_start" + (( i >= _Dbg_stack_size - 1 )) && return 1 # Figure out which index in BASH_ARGV is position "i" (the place where # we start our stack trace from). variable "r" will be that place. typeset -i adjusted_pos - adjusted_pos=$(_Dbg_frame_adjusted_pos $frame_start) + adjusted_pos=$(_Dbg_frame_adjusted_pos $i) typeset -i arg_count=${BASH_ARGC[$adjusted_pos]} - # echo "arg count is " $arg_count - # echo "adjusted_pos is" $adjusted_pos - # typeset -p BASH_ARGC # Print out parameter list. if (( 0 != ${#BASH_ARGC[@]} )) ; then diff --git a/test/data/info-args.cmd b/test/data/info-args.cmd index 7eb81bc6..4a4bf134 100644 --- a/test/data/info-args.cmd +++ b/test/data/info-args.cmd @@ -5,4 +5,6 @@ info args c hanoi info args info functions ^ha +info args 3 +info args 100 quit diff --git a/test/data/info-args.right b/test/data/info-args.right index 1cf8ced4..39d0cd53 100644 --- a/test/data/info-args.right +++ b/test/data/info-args.right @@ -19,5 +19,7 @@ $3 = b $4 = c +info functions ^ha hanoi -+quit ++info args 3 ++info args 100 ++quit bashdb: That's all, folks...