Re: [PATCH 15/26] gdbserver: check for nullptr condition in regcache::get_register_status

Simon Marchi
2023-12-21T21:34:28Z

On 2/28/23 06:28, Tankut Baris Aktemur via Gdb-patches wrote:
> A regcache can be initialized with a register value buffer, in which
> case, the register_status pointer is null. This condition is checked
> in set_register_status, but not in get_register_status. Do this check
> for consistence and safety.
> ---
> gdbserver/regcache.cc | 5 ++++-
> 1 file changed, 4 insertions(+), 1 deletion(-)
>
> diff --git a/gdbserver/regcache.cc b/gdbserver/regcache.cc
> index ec11082be6f..0c6f1eb392b 100644
> --- a/gdbserver/regcache.cc
> +++ b/gdbserver/regcache.cc
> @@ -489,7 +489,10 @@ regcache::get_register_status (int regnum) const
> {
> #ifndef IN_PROCESS_AGENT
> gdb_assert (regnum >= 0 && regnum < tdesc->reg_defs.size ());
> - return (enum register_status) (register_status[regnum]);
> + if (register_status != nullptr)
> + return (enum register_status) (register_status[regnum]);
> + else
> + return REG_VALID;
> #else
> return REG_VALID;
> #endif
> --
> 2.25.1

Thanks, that LGTM, I think it can be pushed on its own.

Approved-By: Simon Marchi <simon.marchi@efficios.com>

Simon