public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Tom Tromey <tromey@adacore.com>
To: gdb-patches@sourceware.org
Cc: Tom Tromey <tromey@adacore.com>
Subject: [PATCH 2/3] Fix latent bug in Python breakpoint creation
Date: Thu,  8 Dec 2022 12:18:03 -0700	[thread overview]
Message-ID: <20221208191804.3819129-3-tromey@adacore.com> (raw)
In-Reply-To: <20221208191804.3819129-1-tromey@adacore.com>

While working on the previous patch, I noticed that Python breakpoint
creation does:

-	  = (qualified != NULL && PyObject_IsTrue (qualified)

PyObject_IsTrue can fail, so this is missing an error check.  This
patch adds the missing check.

Note that this could probably be improved by using the "p" format in
the call to gdb_PyArg_ParseTupleAndKeywords, but that was added in
Python 3.3, and I think gdb still supports 3.2.
---
 gdb/python/py-breakpoint.c | 16 ++++++++++++----
 1 file changed, 12 insertions(+), 4 deletions(-)

diff --git a/gdb/python/py-breakpoint.c b/gdb/python/py-breakpoint.c
index 917fd367d06..39d9bd5dff6 100644
--- a/gdb/python/py-breakpoint.c
+++ b/gdb/python/py-breakpoint.c
@@ -818,7 +818,7 @@ bppy_init_validate_args (const char *spec, char *source,
 static void
 bppy_create_breakpoint (enum bptype type, int access_type, int temporary_bp,
 			int internal_bp, const char *spec,
-			PyObject *qualified, const char *source,
+			int qualified, const char *source,
 			const char *function, const char *label,
 			const char *line)
 {
@@ -829,7 +829,7 @@ bppy_create_breakpoint (enum bptype type, int access_type, int temporary_bp,
       {
 	location_spec_up locspec;
 	symbol_name_match_type func_name_match_type
-	  = (qualified != NULL && PyObject_IsTrue (qualified)
+	  = (qualified
 	     ? symbol_name_match_type::FULL
 	     : symbol_name_match_type::WILD);
 
@@ -916,14 +916,15 @@ bppy_init (PyObject *self, PyObject *args, PyObject *kwargs)
   char *label = NULL;
   char *source = NULL;
   char *function = NULL;
-  PyObject * qualified = NULL;
+  PyObject *qualified_obj = nullptr;
+  int qualified = 0;
 
   if (!gdb_PyArg_ParseTupleAndKeywords (args, kwargs, "|siiOOsssOO", keywords,
 					&spec, &type, &access_type,
 					&internal,
 					&temporary, &source,
 					&function, &label, &lineobj,
-					&qualified))
+					&qualified_obj))
     return -1;
 
 
@@ -955,6 +956,13 @@ bppy_init (PyObject *self, PyObject *args, PyObject *kwargs)
 	return -1;
     }
 
+  if (qualified_obj != nullptr)
+    {
+      qualified = PyObject_IsTrue (qualified_obj);
+      if (qualified == -1)
+	return -1;
+    }
+
   if (bppy_init_validate_args (spec, source, function, label, line.get (),
 			       type) == -1)
     return -1;
-- 
2.34.3


  parent reply	other threads:[~2022-12-08 19:18 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-12-08 19:18 [PATCH 0/3] Add "announce" flag to " Tom Tromey
2022-12-08 19:18 ` [PATCH 1/3] Refactor body of bppy_init Tom Tromey
2022-12-08 19:18 ` Tom Tromey [this message]
2023-01-12 17:44   ` [PATCH 2/3] Fix latent bug in Python breakpoint creation Simon Marchi
2022-12-08 19:18 ` [PATCH 3/3] Let Python breakpoints be created silently Tom Tromey
2023-01-11 17:31   ` Tom Tromey
2023-01-12  9:42     ` Eli Zaretskii
2023-01-12 17:49   ` Simon Marchi
2023-01-13 18:55     ` Tom Tromey
2023-01-13 12:59   ` Pedro Alves
2023-01-13 18:56     ` Tom Tromey

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20221208191804.3819129-3-tromey@adacore.com \
    --to=tromey@adacore.com \
    --cc=gdb-patches@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).