Skip to content

Commit

Permalink
Don't crash on invalid checkpoint numbers
Browse files Browse the repository at this point in the history
Resolves #3764
  • Loading branch information
rocallahan committed Jun 16, 2024
1 parent ca36c98 commit 1628175
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 1 deletion.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1650,6 +1650,7 @@ set(TESTS_WITHOUT_PROGRAM
call_exit
check_patched_pthread
checkpoint_async_signal_syscalls_1000
checkpoint_invalid
checkpoint_mmap_shared
checkpoint_prctl_name
checkpoint_simple
Expand Down
6 changes: 5 additions & 1 deletion src/DebuggerExtensionCommand.cc
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,11 @@ string invoke_delete_checkpoint(GdbServer& gdb_server, Task*,
if (!gdb_server.timeline()) {
return string("Command requires a full debugging session.");
}
int id = stoi(args[0]);
char* endptr;
long id = strtol(args[0].c_str(), &endptr, 10);
if (*endptr) {
return string("Invalid checkpoint number ") + args[0] + ".";
}
auto it = gdb_server.checkpoints.find(id);
if (it != gdb_server.checkpoints.end()) {
if (it->second.is_explicit == GdbServer::Checkpoint::EXPLICIT) {
Expand Down
21 changes: 21 additions & 0 deletions src/test/checkpoint_invalid.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
from util import *

send_gdb('delete checkpoint')
expect_gdb('requires an argument')

send_gdb('delete checkpoint x')
expect_gdb('Invalid checkpoint number')

send_gdb('delete checkpoint 0x1')
expect_gdb('Invalid checkpoint number')

send_gdb('delete checkpoint -1')
expect_gdb('No checkpoint number')

send_gdb('delete checkpoint 0')
expect_gdb('No checkpoint number')

send_gdb('delete checkpoint 99999999999999999999999999999999999999999')
expect_gdb('No checkpoint number')

ok()
3 changes: 3 additions & 0 deletions src/test/checkpoint_invalid.run
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
source `dirname $0`/util.sh
record simple$bitness
debug_gdb_only checkpoint_invalid

0 comments on commit 1628175

Please sign in to comment.