From 680d7fd5fcff860a31021845389d4dfeb7b42e3c Mon Sep 17 00:00:00 2001 From: Tom Tromey Date: Wed, 24 Apr 2019 06:50:01 -0600 Subject: Avoid undefined behavior in Guile exception handling The Guile code will longjmp (via scm_throw) when an object requiring destruction is on the stack. This is undefined behavior. This changes this code to run any destructors in inner scopes, and to pass a POD to gdbscm_throw_gdb_exception. gdb/ChangeLog 2019-04-25 Tom Tromey * guile/scm-exception.c (gdbscm_scm_from_gdb_exception) (gdbscm_throw_gdb_exception): Take a gdbscm_gdb_exception. * guile/scm-block.c, guile/scm-breakpoint.c, guile/scm-cmd.c, guile/scm-disasm.c, guile/scm-frame.c, guile/scm-lazy-string.c, guile/scm-math.c, guile/scm-param.c, guile/scm-ports.c, guile/scm-symbol.c, guile/scm-symtab.c, guile/scm-type.c, guile/scm-value.c: Use unpack. * guile/guile-internal.h (gdbscm_scm_from_gdb_exception): Take a gdbscm_gdb_exception. (gdbscm_throw_gdb_exception): Likewise. (struct gdbscm_gdb_exception): New. (unpack): New function. (gdbscm_wrap): Use unpack. --- gdb/guile/scm-exception.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'gdb/guile/scm-exception.c') diff --git a/gdb/guile/scm-exception.c b/gdb/guile/scm-exception.c index 44cd7b3..e519ad8 100644 --- a/gdb/guile/scm-exception.c +++ b/gdb/guile/scm-exception.c @@ -428,7 +428,7 @@ gdbscm_throw (SCM exception) /* Convert a GDB exception to a object. */ SCM -gdbscm_scm_from_gdb_exception (struct gdb_exception exception) +gdbscm_scm_from_gdb_exception (const gdbscm_gdb_exception &exception) { SCM key; @@ -446,7 +446,7 @@ gdbscm_scm_from_gdb_exception (struct gdb_exception exception) return gdbscm_make_error (key, NULL, "~A", scm_list_1 (gdbscm_scm_from_c_string - (exception.what ())), + (exception.message)), SCM_BOOL_F); } @@ -454,9 +454,11 @@ gdbscm_scm_from_gdb_exception (struct gdb_exception exception) This function does not return. */ void -gdbscm_throw_gdb_exception (struct gdb_exception exception) +gdbscm_throw_gdb_exception (gdbscm_gdb_exception exception) { - gdbscm_throw (gdbscm_scm_from_gdb_exception (exception)); + SCM scm_exception = gdbscm_scm_from_gdb_exception (exception); + xfree (exception.message); + gdbscm_throw (scm_exception); } /* Print the error message portion of an exception. -- cgit v1.1