Avoid undefined behavior in gdbscm_make_breakpoint
authorPedro Alves <pedro@palves.net>
Fri, 1 Apr 2022 13:31:18 +0000 (14:31 +0100)
committerPedro Alves <pedro@palves.net>
Mon, 4 Apr 2022 19:48:48 +0000 (20:48 +0100)
commit4994e74b7abae108000cfab8fa621473f2b11cff
treed1ee2915a783f9d6e7e1de44b579cecf7bd6b2b8
parentd4da1b2c1b7b85968da608dde03e054cc0b1f7ca
Avoid undefined behavior in gdbscm_make_breakpoint

Running gdb.guile/scm-breakpoint.exp against an --enable-ubsan build,
we see:

 UNRESOLVED: gdb.guile/scm-breakpoint.exp: test_watchpoints: create a breakpoint with an invalid type number
 ...
 guile (define wp2 (make-breakpoint "result" #:wp-class WP_WRITE #:type 999))
 ../../src/gdb/guile/scm-breakpoint.c:377:11: runtime error: load of value 999, which is not a valid value for type 'bptype'
 ERROR: GDB process no longer exists

Fix this by parsing the user/guile input as plain int, and cast to
internal type only after we know we have a number that would be valid.

Change-Id: I03578d07db00be01b610a8f5ce72e5521aea6a4b
gdb/guile/scm-breakpoint.c