Fix crash in gdbpy_parse_register_id
I noticed that gdbpy_parse_register_id would assert if passed a Python object of a type it was not expecting. The included test case shows this crash. This patch fixes the problem and also changes gdbpy_parse_register_id to be more "Python-like" -- it always ensures the Python error is set when it fails, and the callers now simply propagate the existing exception.
This commit is contained in:
parent
12f26cb22e
commit
bdc8cfc1e4
7 changed files with 48 additions and 20 deletions
|
@ -253,10 +253,7 @@ frapy_read_register (PyObject *self, PyObject *args)
|
|||
|
||||
if (!gdbpy_parse_register_id (get_frame_arch (frame), pyo_reg_id,
|
||||
®num))
|
||||
{
|
||||
PyErr_SetString (PyExc_ValueError, "Bad register");
|
||||
return NULL;
|
||||
}
|
||||
return nullptr;
|
||||
|
||||
gdb_assert (regnum >= 0);
|
||||
val = value_of_register (regnum, frame);
|
||||
|
|
|
@ -381,21 +381,27 @@ gdbpy_parse_register_id (struct gdbarch *gdbarch, PyObject *pyo_reg_id,
|
|||
{
|
||||
*reg_num = user_reg_map_name_to_regnum (gdbarch, reg_name.get (),
|
||||
strlen (reg_name.get ()));
|
||||
return *reg_num >= 0;
|
||||
if (*reg_num >= 0)
|
||||
return true;
|
||||
PyErr_SetString (PyExc_ValueError, "Bad register");
|
||||
}
|
||||
}
|
||||
/* The register could be its internal GDB register number. */
|
||||
else if (PyLong_Check (pyo_reg_id))
|
||||
{
|
||||
long value;
|
||||
if (gdb_py_int_as_long (pyo_reg_id, &value) && (int) value == value)
|
||||
if (gdb_py_int_as_long (pyo_reg_id, &value) == 0)
|
||||
{
|
||||
if (user_reg_map_regnum_to_name (gdbarch, value) != NULL)
|
||||
{
|
||||
*reg_num = (int) value;
|
||||
return true;
|
||||
}
|
||||
/* Nothing -- error. */
|
||||
}
|
||||
else if ((int) value == value
|
||||
&& user_reg_map_regnum_to_name (gdbarch, value) != NULL)
|
||||
{
|
||||
*reg_num = (int) value;
|
||||
return true;
|
||||
}
|
||||
else
|
||||
PyErr_SetString (PyExc_ValueError, "Bad register");
|
||||
}
|
||||
/* The register could be a gdb.RegisterDescriptor object. */
|
||||
else if (PyObject_IsInstance (pyo_reg_id,
|
||||
|
@ -412,6 +418,8 @@ gdbpy_parse_register_id (struct gdbarch *gdbarch, PyObject *pyo_reg_id,
|
|||
PyErr_SetString (PyExc_ValueError,
|
||||
_("Invalid Architecture in RegisterDescriptor"));
|
||||
}
|
||||
else
|
||||
PyErr_SetString (PyExc_TypeError, _("Invalid type for register"));
|
||||
|
||||
gdb_assert (PyErr_Occurred ());
|
||||
return false;
|
||||
|
|
|
@ -260,10 +260,7 @@ unwind_infopy_add_saved_register (PyObject *self, PyObject *args)
|
|||
&pyo_reg_id, &pyo_reg_value))
|
||||
return NULL;
|
||||
if (!gdbpy_parse_register_id (pending_frame->gdbarch, pyo_reg_id, ®num))
|
||||
{
|
||||
PyErr_SetString (PyExc_ValueError, "Bad register");
|
||||
return NULL;
|
||||
}
|
||||
return nullptr;
|
||||
|
||||
/* If REGNUM identifies a user register then *maybe* we can convert this
|
||||
to a real (i.e. non-user) register. The maybe qualifier is because we
|
||||
|
@ -381,10 +378,7 @@ pending_framepy_read_register (PyObject *self, PyObject *args)
|
|||
if (!PyArg_UnpackTuple (args, "read_register", 1, 1, &pyo_reg_id))
|
||||
return NULL;
|
||||
if (!gdbpy_parse_register_id (pending_frame->gdbarch, pyo_reg_id, ®num))
|
||||
{
|
||||
PyErr_SetString (PyExc_ValueError, "Bad register");
|
||||
return NULL;
|
||||
}
|
||||
return nullptr;
|
||||
|
||||
try
|
||||
{
|
||||
|
|
|
@ -819,7 +819,8 @@ typedef std::unique_ptr<Py_buffer, Py_buffer_deleter> Py_buffer_up;
|
|||
|
||||
If a register is parsed successfully then *REG_NUM will have been
|
||||
updated, and true is returned. Otherwise the contents of *REG_NUM are
|
||||
undefined, and false is returned.
|
||||
undefined, and false is returned. When false is returned, the
|
||||
Python error is set.
|
||||
|
||||
The PYO_REG_ID object can be a string, the name of the register. This
|
||||
is the slowest approach as GDB has to map the name to a number for each
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue