mirror of
https://github.com/php/php-src.git
synced 2026-04-24 08:28:26 +02:00
A few general segfault fixes
This commit is contained in:
@@ -539,11 +539,11 @@ static size_t phpdbg_stdiop_write(php_stream *stream, const char *buf, size_t co
|
||||
}
|
||||
|
||||
if (stat[0].st_dev == stat[1].st_dev && stat[0].st_ino == stat[1].st_ino) {
|
||||
phpdbg_script(P_STDOUT, "%.*s", buf, count);
|
||||
phpdbg_script(P_STDOUT, "%.*s", (int) count, buf);
|
||||
return count;
|
||||
}
|
||||
if (stat[2].st_dev == stat[1].st_dev && stat[2].st_ino == stat[1].st_ino) {
|
||||
phpdbg_script(P_STDERR, "%.*s", buf, count);
|
||||
phpdbg_script(P_STDERR, "%.*s", (int) count, buf);
|
||||
return count;
|
||||
}
|
||||
break;
|
||||
@@ -1244,10 +1244,15 @@ phpdbg_main:
|
||||
sigaction(SIGBUS, &signal_struct, &PHPDBG_G(old_sigsegv_signal));
|
||||
#endif
|
||||
|
||||
php_output_activate(TSRMLS_C);
|
||||
php_output_deactivate(TSRMLS_C);
|
||||
|
||||
php_output_activate(TSRMLS_C);
|
||||
|
||||
if (php_request_startup(TSRMLS_C) == SUCCESS) {
|
||||
int i;
|
||||
|
||||
SG(request_info).argc = argc - php_optind + 1;
|
||||
|
||||
SG(request_info).argc = argc - php_optind + 1;
|
||||
SG(request_info).argv = emalloc(SG(request_info).argc * sizeof(char *));
|
||||
for (i = SG(request_info).argc; --i;) {
|
||||
SG(request_info).argv[i] = estrdup(argv[php_optind - 1 + i]);
|
||||
@@ -1257,10 +1262,6 @@ phpdbg_main:
|
||||
php_hash_environment(TSRMLS_C);
|
||||
}
|
||||
|
||||
/* make sure to turn off buffer for ev command */
|
||||
php_output_activate(TSRMLS_C);
|
||||
php_output_deactivate(TSRMLS_C);
|
||||
|
||||
/* do not install sigint handlers for remote consoles */
|
||||
/* sending SIGINT then provides a decent way of shutting down the server */
|
||||
#ifndef _WIN32
|
||||
@@ -1425,7 +1426,7 @@ phpdbg_out:
|
||||
}
|
||||
phpdbg_out:
|
||||
#endif
|
||||
|
||||
|
||||
{
|
||||
int i;
|
||||
/* free argv */
|
||||
@@ -1438,8 +1439,7 @@ phpdbg_out:
|
||||
#ifndef ZTS
|
||||
/* force cleanup of auto and core globals */
|
||||
zend_hash_clean(CG(auto_globals));
|
||||
memset(
|
||||
&core_globals, 0, sizeof(php_core_globals));
|
||||
memset( &core_globals, 0, sizeof(php_core_globals));
|
||||
#endif
|
||||
if (ini_entries) {
|
||||
free(ini_entries);
|
||||
@@ -1448,15 +1448,17 @@ phpdbg_out:
|
||||
if (ini_override) {
|
||||
free(ini_override);
|
||||
}
|
||||
|
||||
|
||||
/* this must be forced */
|
||||
CG(unclean_shutdown) = 0;
|
||||
|
||||
|
||||
/* this is just helpful */
|
||||
PG(report_memleaks) = 0;
|
||||
|
||||
php_request_shutdown((void*)0);
|
||||
|
||||
php_output_deactivate(TSRMLS_C);
|
||||
|
||||
zend_try {
|
||||
php_module_shutdown(TSRMLS_C);
|
||||
} zend_end_try();
|
||||
@@ -1468,7 +1470,7 @@ phpdbg_out:
|
||||
if (cleaning || remote) {
|
||||
goto phpdbg_main;
|
||||
}
|
||||
|
||||
|
||||
#ifdef ZTS
|
||||
/* bugggy */
|
||||
/* tsrm_shutdown(); */
|
||||
@@ -1483,7 +1485,7 @@ phpdbg_out:
|
||||
if (sapi_name) {
|
||||
free(sapi_name);
|
||||
}
|
||||
|
||||
|
||||
#ifdef _WIN32
|
||||
free(bp_tmp_file);
|
||||
#else
|
||||
|
||||
@@ -763,6 +763,9 @@ PHPDBG_API int phpdbg_stack_execute(phpdbg_param_t *stack TSRMLS_DC) {
|
||||
|
||||
if (handler) {
|
||||
if (phpdbg_stack_verify(handler, &top TSRMLS_CC) == SUCCESS) {
|
||||
phpdbg_activate_err_buf(0 TSRMLS_CC);
|
||||
phpdbg_free_err_buf(TSRMLS_C);
|
||||
|
||||
return handler->handler(top TSRMLS_CC);
|
||||
}
|
||||
}
|
||||
|
||||
+5
-2
@@ -161,6 +161,9 @@ static inline int phpdbg_call_register(phpdbg_param_t *stack TSRMLS_DC) /* {{{ *
|
||||
fci.param_count = 0;
|
||||
}
|
||||
|
||||
phpdbg_activate_err_buf(0 TSRMLS_CC);
|
||||
phpdbg_free_err_buf(TSRMLS_C);
|
||||
|
||||
phpdbg_debug("created %d params from arguments", fci.param_count);
|
||||
|
||||
zend_call_function(&fci, NULL TSRMLS_CC);
|
||||
@@ -603,11 +606,11 @@ PHPDBG_COMMAND(run) /* {{{ */
|
||||
}
|
||||
|
||||
zend_try {
|
||||
php_output_activate(TSRMLS_C);
|
||||
// php_output_activate(TSRMLS_C);
|
||||
PHPDBG_G(flags) ^= PHPDBG_IS_INTERACTIVE;
|
||||
zend_execute(EG(active_op_array) TSRMLS_CC);
|
||||
PHPDBG_G(flags) ^= PHPDBG_IS_INTERACTIVE;
|
||||
php_output_deactivate(TSRMLS_C);
|
||||
// php_output_deactivate(TSRMLS_C);
|
||||
} zend_catch {
|
||||
EG(active_op_array) = orig_op_array;
|
||||
EG(opline_ptr) = orig_opline;
|
||||
|
||||
+59
-49
@@ -734,7 +734,7 @@ static int format_converter(register buffy *odp, const char *fmt, zend_bool esca
|
||||
}
|
||||
*s_ptr++ = ';';
|
||||
} else {
|
||||
*s_ptr++ = s[i];
|
||||
*s_ptr++ = old_s[i];
|
||||
}
|
||||
} while (i++ < old_slen);
|
||||
}
|
||||
@@ -1082,7 +1082,8 @@ static int phpdbg_process_print(FILE *fp, int type, const char *tag, const char
|
||||
if (msg) {
|
||||
msgoutlen = asprintf(&msgout, "%.*s\n", msglen, msg);
|
||||
} else {
|
||||
msgoutlen = asprintf(&msgout, "\n");
|
||||
msgoutlen = 1;
|
||||
msgout = strdup("\n");
|
||||
}
|
||||
break;
|
||||
|
||||
@@ -1091,7 +1092,8 @@ static int phpdbg_process_print(FILE *fp, int type, const char *tag, const char
|
||||
if (msg) {
|
||||
msgoutlen = asprintf(&msgout, "%.*s\n", msglen, msg);
|
||||
} else {
|
||||
msgoutlen = asprintf(&msgout, "");
|
||||
msgoutlen = 0;
|
||||
msgout = strdup("");
|
||||
}
|
||||
break;
|
||||
|
||||
@@ -1103,7 +1105,7 @@ static int phpdbg_process_print(FILE *fp, int type, const char *tag, const char
|
||||
fprintf(fp, "<stream type=\"%s\">", type == P_STDERR ? "stderr" : "stdout");
|
||||
PHPDBG_G(in_script_xml) = type;
|
||||
}
|
||||
buf = php_escape_html_entities((char *) msg, msglen, (size_t *) &buflen, 0, ENT_NOQUOTES, PG(internal_encoding) && PG(internal_encoding)[0] ? PG(internal_encoding) : (SG(default_charset) ? SG(default_charset) : "UTF-8") TSRMLS_CC);
|
||||
buf = php_escape_html_entities((unsigned char *) msg, msglen, (size_t *) &buflen, 0, ENT_NOQUOTES, PG(internal_encoding) && PG(internal_encoding)[0] ? PG(internal_encoding) : (SG(default_charset) ? SG(default_charset) : "UTF-8") TSRMLS_CC);
|
||||
fprintf(fp, "%.*s", buflen, buf);
|
||||
efree(buf);
|
||||
} else {
|
||||
@@ -1130,7 +1132,7 @@ static int phpdbg_process_print(FILE *fp, int type, const char *tag, const char
|
||||
|
||||
if ((PHPDBG_G(flags) & PHPDBG_WRITE_XML)) {
|
||||
if (msgout) {
|
||||
buf = php_escape_html_entities(msgout, msgoutlen, (size_t *) &buflen, 0, ENT_COMPAT, PG(internal_encoding) && PG(internal_encoding)[0] ? PG(internal_encoding) : (SG(default_charset) ? SG(default_charset) : "UTF-8") TSRMLS_CC);
|
||||
buf = php_escape_html_entities((unsigned char *) msgout, msgoutlen, (size_t *) &buflen, 0, ENT_COMPAT, PG(internal_encoding) && PG(internal_encoding)[0] ? PG(internal_encoding) : (SG(default_charset) ? SG(default_charset) : "UTF-8") TSRMLS_CC);
|
||||
xmloutlen = fprintf(fp, "<%s severity=\"%s\" %.*s msgout=\"%.*s\" />", tag, severity, xmllen, xml, buflen, buf);
|
||||
|
||||
efree(buf);
|
||||
@@ -1148,6 +1150,51 @@ static int phpdbg_process_print(FILE *fp, int type, const char *tag, const char
|
||||
return msgout ? msgoutlen : xmloutlen;
|
||||
} /* }}} */
|
||||
|
||||
PHPDBG_API int phpdbg_vprint(int type TSRMLS_DC, FILE *fp, const char *tag, const char *xmlfmt, const char *strfmt, va_list args) {
|
||||
char *msg = NULL, *xml = NULL;
|
||||
int msglen = 0, xmllen = 0;
|
||||
int len;
|
||||
va_list argcpy;
|
||||
|
||||
if (strfmt != NULL && strlen(strfmt) > 0L) {
|
||||
va_copy(argcpy, args);
|
||||
msglen = phpdbg_xml_vasprintf(&msg, strfmt, 0, argcpy TSRMLS_CC);
|
||||
va_end(argcpy);
|
||||
}
|
||||
|
||||
if (PHPDBG_G(flags) & PHPDBG_WRITE_XML) {
|
||||
if (xmlfmt != NULL && strlen(xmlfmt) > 0L) {
|
||||
va_copy(argcpy, args);
|
||||
xmllen = phpdbg_xml_vasprintf(&xml, xmlfmt, 1, argcpy TSRMLS_CC);
|
||||
va_end(argcpy);
|
||||
}
|
||||
}
|
||||
|
||||
if (PHPDBG_G(err_buf).active && type != P_STDOUT && type != P_STDERR) {
|
||||
PHPDBG_G(err_buf).type = type;
|
||||
PHPDBG_G(err_buf).fp = fp;
|
||||
PHPDBG_G(err_buf).tag = strdup(tag);
|
||||
PHPDBG_G(err_buf).msg = msg;
|
||||
PHPDBG_G(err_buf).msglen = msglen;
|
||||
PHPDBG_G(err_buf).xml = xml;
|
||||
PHPDBG_G(err_buf).xmllen = xmllen;
|
||||
|
||||
return msglen;
|
||||
}
|
||||
|
||||
len = phpdbg_process_print(fp, type, tag, msg, msglen, xml, xmllen TSRMLS_CC);
|
||||
|
||||
if (msg) {
|
||||
free(msg);
|
||||
}
|
||||
|
||||
if (xml) {
|
||||
free(xml);
|
||||
}
|
||||
|
||||
return len;
|
||||
}
|
||||
|
||||
PHPDBG_API void phpdbg_free_err_buf(TSRMLS_D) {
|
||||
if (PHPDBG_G(err_buf).type == 0) {
|
||||
return;
|
||||
@@ -1155,9 +1202,9 @@ PHPDBG_API void phpdbg_free_err_buf(TSRMLS_D) {
|
||||
|
||||
PHPDBG_G(err_buf).type = 0;
|
||||
|
||||
efree(PHPDBG_G(err_buf).tag);
|
||||
efree(PHPDBG_G(err_buf).msg);
|
||||
efree(PHPDBG_G(err_buf).xml);
|
||||
free(PHPDBG_G(err_buf).tag);
|
||||
free(PHPDBG_G(err_buf).msg);
|
||||
free(PHPDBG_G(err_buf).xml);
|
||||
}
|
||||
|
||||
PHPDBG_API void phpdbg_activate_err_buf(zend_bool active TSRMLS_DC) {
|
||||
@@ -1185,52 +1232,15 @@ PHPDBG_API int phpdbg_output_err_buf(const char *tag, const char *xmlfmt, const
|
||||
return len;
|
||||
}
|
||||
|
||||
PHPDBG_API int phpdbg_vprint(int type TSRMLS_DC, FILE *fp, const char *tag, const char *xmlfmt, const char *strfmt, va_list args) {
|
||||
char *msg = NULL, *xml = NULL;
|
||||
int msglen = 0, xmllen = 0;
|
||||
int len;
|
||||
|
||||
if (strfmt != NULL && strlen(strfmt) > 0L) {
|
||||
msglen = phpdbg_xml_vasprintf(&msg, strfmt, 0, args TSRMLS_CC);
|
||||
}
|
||||
|
||||
if (PHPDBG_G(flags) & PHPDBG_WRITE_XML) {
|
||||
if (xmlfmt != NULL && strlen(xmlfmt) > 0L) {
|
||||
xmllen = phpdbg_xml_vasprintf(&xml, xmlfmt, 1, args TSRMLS_CC);
|
||||
}
|
||||
}
|
||||
|
||||
if (PHPDBG_G(err_buf).active && type != P_STDOUT && type != P_STDERR) {
|
||||
PHPDBG_G(err_buf).type = type;
|
||||
PHPDBG_G(err_buf).fp = fp;
|
||||
PHPDBG_G(err_buf).tag = estrdup(tag);
|
||||
PHPDBG_G(err_buf).msg = msg;
|
||||
PHPDBG_G(err_buf).msglen = msglen;
|
||||
PHPDBG_G(err_buf).xml = xml;
|
||||
PHPDBG_G(err_buf).xmllen = xmllen;
|
||||
|
||||
return msglen;
|
||||
}
|
||||
|
||||
len = phpdbg_process_print(fp, type, tag, msg, msglen, xml, xmllen TSRMLS_CC);
|
||||
|
||||
if (msg) {
|
||||
free(msg);
|
||||
}
|
||||
|
||||
if (xml) {
|
||||
free(xml);
|
||||
}
|
||||
|
||||
return len;
|
||||
}
|
||||
|
||||
PHPDBG_API int phpdbg_print(int type TSRMLS_DC, FILE *fp, const char *tag, const char *xmlfmt, const char *strfmt, ...) {
|
||||
va_list args;
|
||||
int len;
|
||||
|
||||
va_start(args, strfmt);
|
||||
phpdbg_vprint(type TSRMLS_CC, fp, tag, xmlfmt, strfmt, args);
|
||||
len = phpdbg_vprint(type TSRMLS_CC, fp, tag, xmlfmt, strfmt, args);
|
||||
va_end(args);
|
||||
|
||||
return len;
|
||||
}
|
||||
|
||||
PHPDBG_API int phpdbg_xml_internal(FILE *fp TSRMLS_DC, const char *fmt, ...) {
|
||||
|
||||
Reference in New Issue
Block a user