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

Message ID 893ba2a52032456c31cbb868c2f2ae4e0661b6e0.1677582745.git.tankut.baris.aktemur@intel.com
State New
Headers
Series gdbserver: refactor regcache and allow gradually populating |

Commit Message

Aktemur, Tankut Baris Feb. 28, 2023, 11:28 a.m. UTC
  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(-)
  

Comments

Simon Marchi Dec. 21, 2023, 9:32 p.m. UTC | #1
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.

Ok, thanks, that answers my question on the previous patch :).

Simon
  
Simon Marchi Dec. 21, 2023, 9:34 p.m. UTC | #2
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
  

Patch

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