Skip to content

Commit adcabcc

Browse files
committed
Add # delimiter to phpdbg commands
1 parent 8fe171a commit adcabcc

9 files changed

+986
-832
lines changed

sapi/phpdbg/phpdbg.c

+10
Original file line numberDiff line numberDiff line change
@@ -1244,6 +1244,11 @@ void phpdbg_signal_handler(int sig, siginfo_t *info, void *context) /* {{{ */
12441244
} /* }}} */
12451245
#endif
12461246

1247+
void phpdbg_sighup_handler(int sig) /* {{{ */
1248+
{
1249+
exit(0);
1250+
} /* }}} */
1251+
12471252
void *phpdbg_malloc_wrapper(size_t size ZEND_FILE_LINE_DC ZEND_FILE_LINE_ORIG_DC) /* {{{ */
12481253
{
12491254
return _zend_mm_alloc(zend_mm_get_heap(), size ZEND_FILE_LINE_RELAY_CC ZEND_FILE_LINE_ORIG_RELAY_CC);
@@ -1613,6 +1618,11 @@ int main(int argc, char **argv) /* {{{ */
16131618

16141619
/* set remote flag to stop service shutting down upon quit */
16151620
remote = 1;
1621+
#ifndef _WIN32
1622+
} else {
1623+
1624+
signal(SIGHUP, phpdbg_sighup_handler);
1625+
#endif
16161626
}
16171627

16181628
mm_heap = zend_mm_get_heap();

sapi/phpdbg/phpdbg_cmd.c

+48-19
Original file line numberDiff line numberDiff line change
@@ -434,8 +434,9 @@ PHPDBG_API void phpdbg_stack_free(phpdbg_param_t *stack) {
434434
PHPDBG_API void phpdbg_stack_push(phpdbg_param_t *stack, phpdbg_param_t *param) {
435435
phpdbg_param_t *next = calloc(1, sizeof(phpdbg_param_t));
436436

437-
if (!next)
437+
if (!next) {
438438
return;
439+
}
439440

440441
*(next) = *(param);
441442

@@ -454,6 +455,16 @@ PHPDBG_API void phpdbg_stack_push(phpdbg_param_t *stack, phpdbg_param_t *param)
454455
stack->len++;
455456
} /* }}} */
456457

458+
/* {{{ */
459+
PHPDBG_API void phpdbg_stack_separate(phpdbg_param_t *param) {
460+
phpdbg_param_t *stack = calloc(1, sizeof(phpdbg_param_t));
461+
462+
stack->type = STACK_PARAM;
463+
stack->next = param->next;
464+
param->next = stack;
465+
stack->top = param->top;
466+
} /* }}} */
467+
457468
PHPDBG_API int phpdbg_stack_verify(const phpdbg_command_t *command, phpdbg_param_t **stack) {
458469
if (command) {
459470
char buffer[128] = {0,};
@@ -466,7 +477,7 @@ PHPDBG_API int phpdbg_stack_verify(const phpdbg_command_t *command, phpdbg_param
466477

467478
/* check for arg spec */
468479
if (!(arg) || !(*arg)) {
469-
if (!top) {
480+
if (!top || top->type == STACK_PARAM) {
470481
return SUCCESS;
471482
}
472483

@@ -506,6 +517,10 @@ PHPDBG_API int phpdbg_stack_verify(const phpdbg_command_t *command, phpdbg_param
506517
}
507518

508519
while (arg && *arg) {
520+
if (top && top->type == STACK_PARAM) {
521+
break;
522+
}
523+
509524
current++;
510525

511526
switch (*arg) {
@@ -528,9 +543,11 @@ PHPDBG_API int phpdbg_stack_verify(const phpdbg_command_t *command, phpdbg_param
528543
case '*': { /* do nothing */ } break;
529544
}
530545

531-
if (top ) {
546+
if (top) {
532547
top = top->next;
533-
} else break;
548+
} else {
549+
break;
550+
}
534551

535552
received++;
536553
arg++;
@@ -644,22 +661,9 @@ PHPDBG_API const phpdbg_command_t *phpdbg_stack_resolve(const phpdbg_command_t *
644661
return NULL;
645662
} /* }}} */
646663

647-
/* {{{ */
648-
PHPDBG_API int phpdbg_stack_execute(phpdbg_param_t *stack, zend_bool allow_async_unsafe) {
649-
phpdbg_param_t *top = NULL;
664+
static int phpdbg_internal_stack_execute(phpdbg_param_t *stack, zend_bool allow_async_unsafe) {
650665
const phpdbg_command_t *handler = NULL;
651-
652-
if (stack->type != STACK_PARAM) {
653-
phpdbg_error("command", "type=\"nostack\"", "The passed argument was not a stack !");
654-
return FAILURE;
655-
}
656-
657-
if (!stack->len) {
658-
phpdbg_error("command", "type=\"emptystack\"", "The stack contains nothing !");
659-
return FAILURE;
660-
}
661-
662-
top = (phpdbg_param_t *) stack->next;
666+
phpdbg_param_t *top = (phpdbg_param_t *) stack->next;
663667

664668
switch (top->type) {
665669
case EVAL_PARAM:
@@ -709,6 +713,31 @@ PHPDBG_API int phpdbg_stack_execute(phpdbg_param_t *stack, zend_bool allow_async
709713
return SUCCESS;
710714
} /* }}} */
711715

716+
/* {{{ */
717+
PHPDBG_API int phpdbg_stack_execute(phpdbg_param_t *stack, zend_bool allow_async_unsafe) {
718+
phpdbg_param_t *top = stack;
719+
720+
if (stack->type != STACK_PARAM) {
721+
phpdbg_error("command", "type=\"nostack\"", "The passed argument was not a stack !");
722+
return FAILURE;
723+
}
724+
725+
if (!stack->len) {
726+
phpdbg_error("command", "type=\"emptystack\"", "The stack contains nothing !");
727+
return FAILURE;
728+
}
729+
730+
do {
731+
if (top->type == STACK_PARAM) {
732+
if (phpdbg_internal_stack_execute(top, allow_async_unsafe) == FAILURE) {
733+
return FAILURE;
734+
}
735+
}
736+
} while ((top = top->next));
737+
738+
return SUCCESS;
739+
} /* }}} */
740+
712741
PHPDBG_API char *phpdbg_read_input(char *buffered) /* {{{ */
713742
{
714743
char buf[PHPDBG_MAX_CMD];

sapi/phpdbg/phpdbg_cmd.h

+1
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ PHPDBG_API int phpdbg_ask_user_permission(const char *question);
137137
* Stack Management
138138
*/
139139
PHPDBG_API void phpdbg_stack_push(phpdbg_param_t *stack, phpdbg_param_t *param);
140+
PHPDBG_API void phpdbg_stack_separate(phpdbg_param_t *param);
140141
PHPDBG_API const phpdbg_command_t *phpdbg_stack_resolve(const phpdbg_command_t *commands, const phpdbg_command_t *parent, phpdbg_param_t **top);
141142
PHPDBG_API int phpdbg_stack_verify(const phpdbg_command_t *command, phpdbg_param_t **stack);
142143
PHPDBG_API int phpdbg_stack_execute(phpdbg_param_t *stack, zend_bool allow_async_unsafe);

0 commit comments

Comments
 (0)