[xdebug-dev] xdebug xdebug/test.sh xdebug/xdebug.c xdebug/xdebug_handler_gdb.c xdebug/xdebug_private.h xdebug/xdebug_superglobals.c xdebug/xdebug_var.c xdebug/xdebug_var.h - Fixed bug #75: xdebug's var_dump implementation is not binary safe

From: Derick Rethans <derick[@]derickrethans.nl>
Date: Tue, 3 Aug 2004 22:46:06 +0200

Date: Tue Aug 3 22:46:06 CEST 2004
User: Derick Rethans
Directory: xdebug

Log Message:
[4.00]
- Fixed bug #75: xdebug's var_dump implementation is not binary safe
- Fixed problem with outputing Local Variables
- Fixed bug #83: More than 32 parameters functions make xdebug crash

Modified files:
           xdebug/test.sh (version: 1.13)
           xdebug/xdebug.c (version: 1.230)
           xdebug/xdebug_handler_gdb.c (version: 1.76)
           xdebug/xdebug_private.h (version: 1.12)
           xdebug/xdebug_superglobals.c (version: 1.14)
           xdebug/xdebug_var.c (version: 1.49)
           xdebug/xdebug_var.h (version: 1.18)

[FILE: /xdebug/test.sh]

===================================================================
RCS file: cvstemp,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -r1.12 -r1.13
--- xdebug/test.sh:1.12 Fri Jul 02 11:50:29 2004 GMT
+++ xdebug/test.sh Tue Aug 03 18:46:06 2004 GMT
@@ -1 +1 @@
-TEST_PHP_EXECUTABLE=`which php-4.3dev` php-4.3dev /dat/dev/php/php-4.3dev/run-tests.php tests/*.phpt
+TEST_PHP_EXECUTABLE=`which php-5.0dev` php-5.0dev /dat/dev/php/php-5.0dev/run-tests.php tests/*.phpt

[FILE: /xdebug/xdebug.c]

===================================================================
RCS file: cvstemp,v
retrieving revision 1.229
retrieving revision 1.230
diff -u -r1.229 -r1.230
--- xdebug/xdebug.c:1.229 Fri Jul 16 19:42:05 2004 GMT
+++ xdebug/xdebug.c Tue Aug 03 18:46:06 2004 GMT
@@ -456,9 +456,11 @@
                         xdfree(e->filename);
                 }
 
- for (i = 0; i < e->varc; i++) {
- if (e->vars[i].name) {
- xdfree(e->vars[i].name);
+ if (e->var) {
+ for (i = 0; i < e->varc; i++) {
+ if (e->var[i].name) {
+ xdfree(e->var[i].name);
+ }
                         }
                 }
 
@@ -697,6 +699,7 @@
         int i = 0;
 
         tmp = xdmalloc (sizeof (function_stack_entry));
+ tmp->var = NULL;
         tmp->varc = 0;
         tmp->refcount = 1;
         tmp->level = XG(level);
@@ -763,8 +766,9 @@
                         int is_var;
 
                         param = get_zval(&zdata->opline->op1, zdata->Ts, &is_var);
- tmp->vars[tmp->varc].name = NULL;
- tmp->vars[tmp->varc].addr = param;
+ tmp->var = xdmalloc(sizeof (xdebug_var));
+ tmp->var[tmp->varc].name = NULL;
+ tmp->var[tmp->varc].addr = param;
                         tmp->varc++;
                 } else if (XG(collect_includes)) {
                         tmp->include_filename = xdstrdup(zend_get_executed_filename(TSRMLS_C));
@@ -776,12 +780,13 @@
                         tmp->lineno = cur_opcode->lineno;
                 }
                 if (XG(collect_params)) {
+ tmp->var = xdmalloc(arg_count * sizeof (xdebug_var));
                         for (i = 0; i < arg_count; i++) {
- tmp->vars[tmp->varc].name = NULL;
+ tmp->var[tmp->varc].name = NULL;
                                 if (zend_ptr_stack_get_arg(tmp->varc + 1, (void**) &param TSRMLS_CC) == SUCCESS) {
- tmp->vars[tmp->varc].addr = *param;
+ tmp->var[tmp->varc].addr = *param;
                                 } else {
- tmp->vars[tmp->varc].addr = NULL;
+ tmp->var[tmp->varc].addr = NULL;
                                 }
                                 tmp->varc++;
                         }
@@ -1104,6 +1109,7 @@
 static void dump_used_var_with_contents(void *htmlq, xdebug_hash_element* he)
 {
         int html = *(int *)htmlq;
+ int len;
         zval *zvar;
         char *contents;
         char *name = (char*) he->ptr;
@@ -1128,18 +1134,20 @@
                 return;
         }
         if (html) {
- contents = get_zval_value_fancy(NULL, zvar TSRMLS_CC);
+ contents = get_zval_value_fancy(NULL, zvar, &len TSRMLS_CC);
                 if (contents) {
- php_printf("<tr><td colspan='2' align='right' bgcolor='#ccffcc'>$%s = </td><td bgcolor='#ccffcc'>%s</td></tr>\n", name, contents);
+ php_printf("<tr><td colspan='2' align='right' bgcolor='#ccffcc'>$%s = </td><td bgcolor='#ccffcc'>", name);
+ PHPWRITE(contents, len);
+ php_printf("</td></tr>\n");
                 } else {
                         php_printf("<tr><td bgcolor='#ccffcc'>$%s</td><td bgcolor='#ccffcc' colspan='2'><i>Undefined</i></td></tr>\n", name);
                 }
         } else {
                 contents = get_zval_value(zvar);
                 if (contents) {
- printf(" $%s = %s\n", name, contents);
+ php_printf(" $%s = %s\n", name, contents);
                 } else {
- printf(" $%s = *uninitialized*\n", name);
+ php_printf(" $%s = *uninitialized*\n", name);
                 }
         }
         xdfree(contents);
@@ -1152,6 +1160,7 @@
         xdebug_llist_element *le;
         int is_cli = (strcmp("cli", sapi_module.name) == 0);
         function_stack_entry *i;
+ int len;
 
         if (html && !log_only) {
                 php_printf("<br />\n<font size='1'><table border='1' cellspacing='0'>\n");
@@ -1216,12 +1225,12 @@
                                 } else {
                                         c = 1;
                                 }
- tmp_varname = i->vars[j].name ? xdebug_sprintf("$%s = ", i->vars[j].name) : xdstrdup("");
- tmp_value = get_zval_value(i->vars[j].addr);
+ tmp_varname = i->var[j].name ? xdebug_sprintf("$%s = ", i->var[j].name) : xdstrdup("");
+ tmp_value = get_zval_value(i->var[j].addr);
                                 if (!log_only) {
                                         if (html) {
- tmp_fancy_value = get_zval_value_fancy(tmp_varname, i->vars[j].addr TSRMLS_CC);
- php_printf("%s", tmp_fancy_value);
+ tmp_fancy_value = get_zval_value_fancy(tmp_varname, i->var[j].addr, &len TSRMLS_CC);
+ PHPWRITE(tmp_fancy_value, len);
                                                 xdfree(tmp_fancy_value);
                                         } else {
                                                 php_printf("%s%s", tmp_varname, tmp_value);
@@ -1268,7 +1277,7 @@
                                                 php_printf("<tr><th colspan='3' bgcolor='#33aa33'>Variables in local scope</th></tr>\n");
                                                 php_printf("<tr><th colspan='2' bgcolor='#55cc55'>Variable</th><th bgcolor='#55cc55'>Value</th></tr>\n");
                                         } else {
- printf("\n\nVariables in local scope:\n");
+ php_printf("\n\nVariables in local scope:\n");
                                         }
                                         xdebug_hash_apply(i->used_vars, (void*) &html, dump_used_var_with_contents);
                                 }
@@ -1339,10 +1348,10 @@
                         c = 1;
                 }
 
- tmp_varname = i->vars[j].name ? xdebug_sprintf("$%s = ", i->vars[j].name) : xdstrdup("");
+ tmp_varname = i->var[j].name ? xdebug_sprintf("$%s = ", i->var[j].name) : xdstrdup("");
                 xdebug_str_add(&str, tmp_varname, 1);
 
- tmp_value = get_zval_value(i->vars[j].addr);
+ tmp_value = get_zval_value(i->var[j].addr);
                 xdebug_str_add(&str, tmp_value, 1);
         }
 
@@ -1569,9 +1578,9 @@
                 MAKE_STD_ZVAL(params);
                 array_init(params);
                 for (j = 0; j < i->varc; j++) {
- argument = get_zval_value(i->vars[j].addr);
- if (i->vars[j].name) {
- add_assoc_string_ex(params, i->vars[j].name, strlen(i->vars[j].name) + 1, argument, 1);
+ argument = get_zval_value(i->var[j].addr);
+ if (i->var[j].name) {
+ add_assoc_string_ex(params, i->var[j].name, strlen(i->var[j].name) + 1, argument, 1);
                         } else {
                                 add_index_string(params, j, argument, 1);
                         }
@@ -1684,7 +1693,7 @@
 {
         zval ***args;
         int argc;
- int i;
+ int i, len;
         char *val;
         
         argc = ZEND_NUM_ARGS();
@@ -1697,8 +1706,8 @@
         
         for (i = 0; i < argc; i++) {
                 if (PG(html_errors)) {
- val = get_zval_value_fancy(NULL, (zval*) *args[i] TSRMLS_CC);
- PHPWRITE(val, strlen(val));
+ val = get_zval_value_fancy(NULL, (zval*) *args[i], &len TSRMLS_CC);
+ PHPWRITE(val, len);
                         xdfree(val);
                 } else {
                         xdebug_php_var_dump(args[i], 1 TSRMLS_CC);

[FILE: /xdebug/xdebug_handler_gdb.c]

===================================================================
RCS file: cvstemp,v
retrieving revision 1.75
retrieving revision 1.76
diff -u -r1.75 -r1.76
--- xdebug/xdebug_handler_gdb.c:1.75 Wed Apr 21 16:19:31 2004 GMT
+++ xdebug/xdebug_handler_gdb.c Tue Aug 03 18:46:06 2004 GMT
@@ -187,6 +187,7 @@
         char *tmp;
         char *ret;
         char *type;
+ int len;
 
         if ((error_code & XDEBUG_E) == XDEBUG_E) {
                 type = "error";
@@ -196,7 +197,8 @@
         
         switch (options->response_format) {
                 case XDEBUG_RESPONSE_XML:
- tmp = xmlize(message);
+ /* we ignore binary safety here */
+ tmp = xmlize(message, strlen(message), &len);
                         ret = xdebug_sprintf("<xdebug><%s><code>%d</code><message>%s</message></%s></xdebug>", type, error_code, tmp, type);
                         efree(tmp);
                         return ret;
@@ -258,13 +260,15 @@
 static inline void show_available_commands_in_group(xdebug_con *h, int fmt, int flag, int test_flag, xdebug_gdb_cmd *ptr)
 {
         char *tmp;
+ int len;
 
         if (flag & test_flag ) {
             while (ptr->name) {
                         if (ptr->show && ptr->help) {
                                 switch (fmt) {
                                         case XDEBUG_RESPONSE_XML:
- tmp = xmlize(ptr->help);
+ /* we ignore binary safety here */
+ tmp = xmlize(ptr->help, strlen(ptr->help), &len);
                                                 SENDMSG(h->socket, xdebug_sprintf("<command><name>%s</name><desc>%s</desc></command>", ptr->name, tmp));
                                                 efree(tmp);
                                                 break;
@@ -302,11 +306,13 @@
 {
         xdebug_gdb_options *o = (xdebug_gdb_options*) h->options;
         char *t1, *t2;
+ int len;
 
         if (cmd) {
                 if (o->response_format == XDEBUG_RESPONSE_XML) {
- t1 = xmlize(cmd->description);
- t2 = xmlize(cmd->help);
+ /* we ignore binary safety here */
+ t1 = xmlize(cmd->description, strlen(cmd->description), &len);
+ t2 = xmlize(cmd->help, strlen(cmd->help), &len);
                         SENDMSG(h->socket, xdebug_sprintf("<xdebug><help><command><syntax>%s</syntax><desc>%s</desc></help</xdebug>\n", t1, t2));
                         efree(t1);
                         efree(t2);
@@ -420,7 +426,7 @@
         fd_buf fd_buffer = { NULL, 0 };
         int i = begin;
         char *line = NULL;
- int update = 0;
+ int update = 0, len;
         char *tmp;
 
         if (i < 0) {
@@ -447,7 +453,8 @@
                 if (line) {
                         update = 1;
                         if (response_format == XDEBUG_RESPONSE_XML) {
- tmp = xmlize(line);
+ /* we ignore binary safety here */
+ tmp = xmlize(line, strlen(line), &len);
                                 SENDMSG(h->socket, xdebug_sprintf("<line file='%s' no='%d'>%s</line>", file, begin + i, tmp));
                                 efree(tmp);
                         } else {
@@ -488,6 +495,7 @@
         char *tmp;
         char *tmp_value;
         int xml = (response_format == XDEBUG_RESPONSE_XML);
+ int len;
         TSRMLS_FETCH();
 /*
 * Breakpoint 2, xdebug_execute (op_array=0x82caf50)
@@ -509,12 +517,13 @@
                         c = 1;
                 }
 
- if (i->vars[j].name) {
- SENDMSG(h->socket, xdebug_sprintf("$%s = ", i->vars[j].name));
+ if (i->var[j].name) {
+ SENDMSG(h->socket, xdebug_sprintf("$%s = ", i->var[j].name));
                 }
- tmp_value = get_zval_value(i->vars[j].addr);
- tmp = xmlize(tmp_value);
- SSEND(h->socket, tmp);
+ tmp_value = get_zval_value(i->var[j].addr);
+ /* we ignore binary safety here */
+ tmp = xmlize(tmp_value, strlen(tmp_value), &len);
+ SSENDL(h->socket, tmp, len);
                 xdfree(tmp_value);
                 efree(tmp);
         }
@@ -533,6 +542,7 @@
         char *tmp_fname;
         char *tmp;
         char *tmp_value;
+ int len;
         TSRMLS_FETCH();
         
 /*
@@ -564,12 +574,13 @@
                         c = 1;
                 }
 
- if (i->vars[j].name) {
- SENDMSG(h->socket, xdebug_sprintf("$%s = ", i->vars[j].name));
+ if (i->var[j].name) {
+ SENDMSG(h->socket, xdebug_sprintf("$%s = ", i->var[j].name));
                 }
- tmp_value = get_zval_value(i->vars[j].addr);
- tmp = xmlize(tmp_value);
- SSEND(h->socket, tmp);
+ tmp_value = get_zval_value(i->var[j].addr);
+ /* we ignore binary safety here */
+ tmp = xmlize(tmp_value, strlen(tmp_value), &len);
+ SSENDL(h->socket, tmp, len);
                 xdfree(tmp_value);
                 efree(tmp);
         }
@@ -1089,10 +1100,12 @@
 static void dump_line_breakpoint(xdebug_con *h, xdebug_gdb_options *options, xdebug_brk_info* brk_info)
 {
         char *condition = NULL;
+ int len;
 
         if (options->response_format == XDEBUG_RESPONSE_XML) {
                 if (condition) {
- condition = xmlize(brk_info->condition);
+ /* we ignore binary safety here */
+ condition = xmlize(brk_info->condition, strlen(brk_info->condition), &len);
                         SENDMSG(h->socket,
                                 xdebug_sprintf("<breakpoint type='line' condition='%s'><file>%s</file><line>%d</line></breakpoint>",
                                 condition,
@@ -1321,7 +1334,7 @@
 
 char *xdebug_gdb_get_revision(void)
 {
- return "$Revision: 1.75 $";
+ return "$Revision: 1.76 $";
 }
 
 int xdebug_gdb_init(xdebug_con *context, int mode)

[FILE: /xdebug/xdebug_private.h]

===================================================================
RCS file: cvstemp,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -r1.11 -r1.12
--- xdebug/xdebug_private.h:1.11 Fri Jun 11 10:42:12 2004 GMT
+++ xdebug/xdebug_private.h Tue Aug 03 18:46:06 2004 GMT
@@ -128,7 +128,6 @@
         xdebug_llist *call_list;
 } xdebug_profile;
 
-#define MAX_FUNCTION_ARGUMENTS 32
 typedef struct _function_stack_entry {
         /* function properties */
         xdebug_func function;
@@ -143,7 +142,7 @@
         /* argument properties */
         int arg_done;
         int varc;
- xdebug_var vars[MAX_FUNCTION_ARGUMENTS];
+ xdebug_var *var;
         zval *return_value;
         xdebug_hash *used_vars;
         HashTable *symbol_table;

[FILE: /xdebug/xdebug_superglobals.c]

===================================================================
RCS file: cvstemp,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -r1.13 -r1.14
--- xdebug/xdebug_superglobals.c:1.13 Thu Dec 18 10:11:22 2003 GMT
+++ xdebug/xdebug_superglobals.c Tue Aug 03 18:46:06 2004 GMT
@@ -32,6 +32,7 @@
 static void dump_hash_elem(zval *z, char *name, char *elem, int html, int log TSRMLS_DC)
 {
         char buffer[1024];
+ int len;
 
         if (html) {
                 php_printf("<tr><td colspan='2' align='right' bgcolor='#ffffcc'>$%s['%s'] =</td>", name, elem);
@@ -41,8 +42,10 @@
                 char *val;
 
                 if (html) {
- val = get_zval_value_fancy(NULL, z TSRMLS_CC);
- php_printf("<td bgcolor='#ffffcc'>%s</td>", val);
+ val = get_zval_value_fancy(NULL, z, &len TSRMLS_CC);
+ php_printf("<td bgcolor='#ffffcc'>");
+ PHPWRITE(val, len);
+ php_printf("</td>");
                 } else {
                         val = get_zval_value(z);
                         printf("\n $%s['%s'] = %s", name, elem, val);

[FILE: /xdebug/xdebug_var.c]

===================================================================
RCS file: cvstemp,v
retrieving revision 1.48
retrieving revision 1.49
diff -u -r1.48 -r1.49
--- xdebug/xdebug_var.c:1.48 Mon Aug 02 20:04:34 2004 GMT
+++ xdebug/xdebug_var.c Tue Aug 03 18:46:06 2004 GMT
@@ -287,6 +287,7 @@
 {
         HashTable *myht;
         char* tmp_str;
+ int newlen;
 
         if (!*struc) {
                 xdebug_str_addl(str, "<uninitialized/>", 16, 0);
@@ -311,9 +312,11 @@
                         break;
 
                 case IS_STRING:
- tmp_str = xmlize(Z_STRVAL_PP(struc));
- xdebug_str_add(str, xdebug_sprintf("<string>%s</string>", tmp_str), 1);
+ xdebug_str_addl(str, "<string>", 8, 0);
+ tmp_str = xmlize(Z_STRVAL_PP(struc), Z_STRLEN_PP(struc), &newlen);
+ xdebug_str_addl(str, tmp_str, newlen, 0);
                         efree(tmp_str);
+ xdebug_str_addl(str, "</string>", 9, 0);
                         break;
 
                 case IS_ARRAY:
@@ -599,6 +602,7 @@
 {
         HashTable *myht;
         char* tmp_str;
+ int newlen;
 
         switch (Z_TYPE_PP(struc)) {
                 case IS_BOOL:
@@ -618,9 +622,11 @@
                         break;
 
                 case IS_STRING:
- tmp_str = xmlize(Z_STRVAL_PP(struc));
- xdebug_str_add(str, xdebug_sprintf("<font color='%s'>'%s'</font>", PURPLE, tmp_str), 1);
+ xdebug_str_add(str, xdebug_sprintf("<font color='%s'>'", PURPLE), 1);
+ tmp_str = xmlize(Z_STRVAL_PP(struc), Z_STRLEN_PP(struc), &newlen);
+ xdebug_str_addl(str, tmp_str, newlen, 0);
                         efree(tmp_str);
+ xdebug_str_addl(str, "'</font>", 8, 0);
                         break;
 
                 case IS_ARRAY:
@@ -677,7 +683,7 @@
         }
 }
 
-char* get_zval_value_fancy(char *name, zval *val TSRMLS_DC)
+char* get_zval_value_fancy(char *name, zval *val, int *len TSRMLS_DC)
 {
         xdebug_str str = {0, 0, NULL};
 
@@ -685,6 +691,7 @@
         xdebug_var_export_fancy(&val, (xdebug_str*) &str, 1 TSRMLS_CC);
         xdebug_str_addl(&str, "</pre>", 6, 0);
 
+ *len = str.l;
         return str.d;
 }
 
@@ -692,13 +699,12 @@
 ** XML encoding function
 */
 
-char* xmlize(char *string)
+char* xmlize(char *string, int len, int *newlen)
 {
- int len = strlen(string);
         char *tmp;
         char *tmp2;
 
- if (strlen(string)) {
+ if (len) {
                 tmp = php_str_to_str(string, len, "&", 1, "&amp;", 5, &len);
 
                 tmp2 = php_str_to_str(tmp, len, ">", 1, "&gt;", 4, &len);
@@ -707,7 +713,7 @@
                 tmp = php_str_to_str(tmp2, len, "<", 1, "&lt;", 4, &len);
                 efree(tmp2);
 
- tmp2 = php_str_to_str(tmp, len, "\n", 1, "&#10;", 5, &len);
+ tmp2 = php_str_to_str(tmp, len, "\n", 1, "&#10;", 5, newlen);
                 efree(tmp);
                 return tmp2;
         } else {

[FILE: /xdebug/xdebug_var.h]

===================================================================
RCS file: cvstemp,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -r1.17 -r1.18
--- xdebug/xdebug_var.h:1.17 Thu Mar 04 10:46:45 2004 GMT
+++ xdebug/xdebug_var.h Tue Aug 03 18:46:06 2004 GMT
@@ -31,11 +31,11 @@
 void xdebug_var_export_fancy(zval **struc, xdebug_str *str, int level TSRMLS_DC);
 void xdebug_var_export_xml_node(zval **struc, char *name, xdebug_xml_node *node, int level TSRMLS_DC);
 
-char* xmlize(char *string);
+char* xmlize(char *string, int len, int *newlen);
 char* error_type (int type);
 char* get_zval_value (zval *val);
 char* get_zval_value_xml (char *name, zval *val);
-char* get_zval_value_fancy(char *name, zval *val TSRMLS_DC);
+char* get_zval_value_fancy(char *name, zval *val, int *len TSRMLS_DC);
 xdebug_xml_node* get_zval_value_xml_node (char *name, zval *val);
 char* show_fname (xdebug_func t, int html, int flags TSRMLS_DC);
 
Received on Tue Aug 03 2004 - 22:46:11 BST

This archive was generated by hypermail 2.2.0 : Sun Jun 24 2018 - 04:00:02 BST