Skip to content

Commit

Permalink
Don't allow "info args n" to use n outside the valid range
Browse files Browse the repository at this point in the history
Max value of n is one less than the current stack depth.
  • Loading branch information
jansorg committed Oct 9, 2024
1 parent f5e83cc commit 5c69adf
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 12 deletions.
15 changes: 4 additions & 11 deletions command/info_sub/args.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
2 changes: 2 additions & 0 deletions test/data/info-args.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,6 @@ info args
c hanoi
info args
info functions ^ha
info args 3
info args 100
quit
4 changes: 3 additions & 1 deletion test/data/info-args.right
Original file line number Diff line number Diff line change
Expand Up @@ -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...

0 comments on commit 5c69adf

Please sign in to comment.