Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions sapi/phpdbg/phpdbg_bp.c
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,12 @@ PHPDBG_API void phpdbg_set_breakpoint_symbol(const char *name, size_t name_len)
{
char *lcname;

if (!name_len) {
phpdbg_error("Empty symbol name");
phpdbg_reset_breakpoints();
return;
}

if (*name == '\\') {
name++;
name_len--;
Expand Down Expand Up @@ -439,11 +445,24 @@ PHPDBG_API void phpdbg_set_breakpoint_method(const char *class_name, const char
size_t func_len = strlen(func_name);
char *func_lcname, *class_lcname;

if (!class_len) {
phpdbg_error("Empty class name");
phpdbg_reset_breakpoints();
return;
}

if (!func_len) {
phpdbg_error("Empty function name");
phpdbg_reset_breakpoints();
return;
}

if (*class_name == '\\') {
class_name++;
class_len--;
}


func_lcname = zend_str_tolower_dup(func_name, func_len);
class_lcname = zend_str_tolower_dup(class_name, class_len);

Expand Down
46 changes: 46 additions & 0 deletions sapi/phpdbg/tests/gh15208.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
--TEST--
GH-15208 (phpdbg segfault on empty class/function names)
--PHPDBG--
r
c
--FILE--
<?php

function test($function) {
if (str_contains($function, "zend")) {
return;
}
ob_start();
try {
@$function();
} catch (Throwable) {
}
try {
@$function(null);
} catch (Throwable) {
}
try {
@$function(null, null);
} catch (Throwable) {
}
ob_end_clean();
}

foreach (get_defined_functions()["internal"] as $function) {
test($function);
}
?>
--EXPECTF--
[Successful compilation of %s]
%a
Notice: ob_end_clean(): Failed to delete buffer. No buffer to delete in %s on line %d
%A
%a
>00009: @$function();
00010: } catch (Throwable) {
00011: }
prompt> [Cannot set breakpoint in %s, it is not a regular file]
[Breakpoint #1 added at ::]
[Breakpoint #2 added at ]
[Script ended normally]
[The stack contains nothing !]
Loading