Fwd: [PATCH] Re: [Sab] Seg Fault with Sablotron
| From: | Melvyn Sopacua | Date: | Mon, 22 Jul 2002 16:04:39 +0000 |
| Subject: | Fwd: [PATCH] Re: [Sab] Seg Fault with Sablotron | ||
| Groups: | php.qa | ||
| Request: | Send a blank email to php-qa+get-5611@lists.php.net to get a copy of this message | ||
I haven't checked this one out completely, but it seems a good patch and
is at least working for me.
Could this be committed for 4.2.3RC1 and get some testing on a wide variaty
of platforms?
>From: Lenar Lõhmus <lenar@vision.ee>
>Organization: Vision Group LLC
>To: sablist@gingerall.cz
>Subject: [PATCH] Re: [Sab] Seg Fault with Sablotron
>Date: Thu, 18 Jul 2002 12:23:01 +0300
>User-Agent: KMail/1.4.2
>Reply-To: sablist@gingerall.cz
>
>
>PHP 4.2.1 is somewhat incompatible with sablotron >= 0.90.
>Problems are with scheme/sax handlers...
>Attached patch fixes those incompatibilities.
>
>Lenar.
>
>On neljapäev, 18. juuli 2002 09:09, William S. wrote:
> > I am getting random Segmentation Faults.
> > The back trace is below. I don't have a
> > problem with scripts _not_ running 'xslt_process'
> > so I am presuming it relates to Sablotron.
> > Any idea what the problem is? Everything seemed
> > to compile OK.
> >
>------------------------------------------------------------------------
>
>Archives and info:
>http://www.gingerall.org/charlie/ga/xml/m_ml.xml
>
>Mailing list maintained by Ginger Alliance
>
>
>
>
>---
>Incoming mail is certified Virus Free.
>Checked by AVG anti-virus system (http://www.grisoft.com).
>Version: 6.0.377 / Virus Database: 211 - Release Date: 7/15/2002
Met vriendelijke groeten / With kind regards,
Webmaster IDG.nl
Melvyn Sopacua
<@Logan> I spent a minute looking at my own code by accident.
<@Logan> I was thinking "What the hell is this guy doing?"
http://www.geekissues.org/quotes/top50.html?6824
--- sablot.c.old Sat May 11 12:10:49 2002 +++ sablot.c Sat May 11 12:58:18 2002 @@ -52,15 +52,15 @@ static int scheme_close(void *, SablotHandle, int); /* Sax handler functions */ -static SAX_RETURN sax_startdoc(void *); -static SAX_RETURN sax_startelement(void *, const char *, const char **); -static SAX_RETURN sax_endelement(void *, const char *); -static SAX_RETURN sax_startnamespace(void *, const char *, const char *); -static SAX_RETURN sax_endnamespace(void *, const char *); -static SAX_RETURN sax_comment(void *, const char *); -static SAX_RETURN sax_pi(void *, const char *, const char *); -static SAX_RETURN sax_characters(void *, const char *, int); -static SAX_RETURN sax_enddoc(void *); +static SAX_RETURN sax_startdoc(void *, SablotHandle); +static SAX_RETURN sax_startelement(void *, SablotHandle, const char *, const char **); +static SAX_RETURN sax_endelement(void *, SablotHandle, const char *); +static SAX_RETURN sax_startnamespace(void *, SablotHandle, const char *, const char *); +static SAX_RETURN sax_endnamespace(void *, SablotHandle, const char *); +static SAX_RETURN sax_comment(void *, SablotHandle, const char *); +static SAX_RETURN sax_pi(void *, SablotHandle, const char *, const char *); +static SAX_RETURN sax_characters(void *, SablotHandle, const char *, int); +static SAX_RETURN sax_enddoc(void *, SablotHandle); /* Error handlers */ static MH_ERROR error_makecode(void *, SablotHandle, int, unsigned short, unsigned short); @@ -723,12 +723,14 @@ xslt_call_function("scheme get all", XSLT_SCHEME(handle).get_all, 3, argv, &retval); - /* Save the return value in the buffer (copying it) */ - *buffer = estrndup(Z_STRVAL_P(retval), Z_STRLEN_P(retval)); - *byte_count = Z_STRLEN_P(retval); + if(retval) { + /* Save the return value in the buffer (copying it) */ + *buffer = estrndup(Z_STRVAL_P(retval), Z_STRLEN_P(retval)); + *byte_count = Z_STRLEN_P(retval); - /* Free return value */ - zval_ptr_dtor(&retval); + /* Free return value */ + zval_ptr_dtor(&retval); + } return 0; } @@ -801,11 +803,13 @@ xslt_call_function("scheme open", XSLT_SCHEME(handle).open, 3, argv, &retval); - /* Return value is a resource pointer to an open file */ - *fd = Z_LVAL_P(retval); + if(retval) { + /* Return value is a resource pointer to an open file */ + *fd = Z_LVAL_P(retval); - /* Free it all up */ - zval_ptr_dtor(&retval); + /* Free it all up */ + zval_ptr_dtor(&retval); + } /* return success */ return 0; @@ -845,11 +849,13 @@ xslt_call_function("scheme get", XSLT_SCHEME(handle).get, 3, argv, &retval); - /* Returns the number of bytes read */ - *byte_count = Z_LVAL_P(retval); + if(retval) { + /* Returns the number of bytes read */ + *byte_count = Z_LVAL_P(retval); - /* Free things up */ - zval_ptr_dtor(&retval); + /* Free things up */ + zval_ptr_dtor(&retval); + } /* return success */ return 0; @@ -889,11 +895,13 @@ xslt_call_function("scheme put", XSLT_SCHEME(handle).put, 3, argv, &retval); - /* The return value is the number of bytes written */ - *byte_count = Z_LVAL_P(retval); + if(retval) { + /* The return value is the number of bytes written */ + *byte_count = Z_LVAL_P(retval); - /* Free everything up */ - zval_ptr_dtor(&retval); + /* Free everything up */ + zval_ptr_dtor(&retval); + } /* Return success */ return 0; @@ -931,7 +939,8 @@ 2, argv, &retval); /* Free everything up */ - zval_ptr_dtor(&retval); + if(retval) + zval_ptr_dtor(&retval); /* Return success */ return 0; @@ -940,7 +949,7 @@ /* {{{ sax_startdoc() Called when the document starts to be processed */ -static SAX_RETURN sax_startdoc(void *ctx) +static SAX_RETURN sax_startdoc(void *ctx, SablotHandle proc) { zval *argv[1]; /* Arguments to the sax start doc function */ zval *retval; /* Return value from sax start doc function */ @@ -964,13 +973,15 @@ 1, argv, &retval); /* Cleanup */ - zval_ptr_dtor(&retval); + if(retval) + zval_ptr_dtor(&retval); } /* }}} */ /* {{{ sax_startelement() Called when an element is begun to be processed */ static SAX_RETURN sax_startelement(void *ctx, + SablotHandle proc, const char *name, const char **attr) { @@ -1012,13 +1023,14 @@ 3, argv, &retval); /* Cleanup */ - zval_ptr_dtor(&retval); + if(retval) + zval_ptr_dtor(&retval); } /* }}} */ /* {{{ xslt_sax_endelement() Called when an ending XML element is encountered */ -static SAX_RETURN sax_endelement(void *ctx, const char *name) +static SAX_RETURN sax_endelement(void *ctx, SablotHandle proc, const char *name) { zval *argv[2]; /* Arguments to the sax end element function */ zval *retval; /* Return value from the sax end element function */ @@ -1046,13 +1058,15 @@ 2, argv, &retval); /* Cleanup */ - zval_ptr_dtor(&retval); + if(retval) + zval_ptr_dtor(&retval); } /* }}} */ /* {{{ sax_startnamespace() Called at the beginning of the parsing of a new namespace */ -static SAX_RETURN sax_startnamespace(void *ctx, +static SAX_RETURN sax_startnamespace(void *ctx, + SablotHandle proc, const char *prefix, const char *uri) { @@ -1085,13 +1099,14 @@ 3, argv, &retval); /* Cleanup */ - zval_ptr_dtor(&retval); + if(retval) + zval_ptr_dtor(&retval); } /* }}} */ /* {{{ sax_endnamespace() Called when a new namespace is finished being parsed */ -static SAX_RETURN sax_endnamespace(void *ctx, const char *prefix) +static SAX_RETURN sax_endnamespace(void *ctx, SablotHandle proc, const char *prefix) { zval *argv[2]; /* Arguments to the sax end namespace function */ zval *retval; /* Return value from the sax end namespace function */ @@ -1119,13 +1134,14 @@ 2, argv, &retval); /* Cleanup */ - zval_ptr_dtor(&retval); + if(retval) + zval_ptr_dtor(&retval); } /* }}} */ /* {{{ sax_comment() Called when a comment is found */ -static SAX_RETURN sax_comment(void *ctx, const char *contents) +static SAX_RETURN sax_comment(void *ctx, SablotHandle proc, const char *contents) { zval *argv[2]; /* Arguments to the sax comment function */ zval *retval; /* Return value from the sax comment function */ @@ -1153,13 +1169,15 @@ 2, argv, &retval); /* Cleanup */ - zval_ptr_dtor(&retval); + if(retval) + zval_ptr_dtor(&retval); } /* }}} */ /* {{{ sax_pi() Called when processing instructions are found */ static SAX_RETURN sax_pi(void *ctx, + SablotHandle proc, const char *target, const char *contents) { @@ -1192,13 +1210,15 @@ 3, argv, &retval); /* Cleanup */ - zval_ptr_dtor(&retval); + if(retval) + zval_ptr_dtor(&retval); } /* }}} */ /* {{{ sax_characters() Called when characters are come upon */ static SAX_RETURN sax_characters(void *ctx, + SablotHandle proc, const char *contents, int length) { @@ -1228,13 +1248,14 @@ 2, argv, &retval); /* Cleanup */ - zval_ptr_dtor(&retval); + if(retval) + zval_ptr_dtor(&retval); } /* }}} */ /* {{{ sax_enddoc() Called when the document is finished being parsed */ -static SAX_RETURN sax_enddoc(void *ctx) +static SAX_RETURN sax_enddoc(void *ctx, SablotHandle proc) { zval *argv[1]; /* Arguments to the end document function */ zval *retval; /* Return value from the end document function */ @@ -1259,7 +1280,8 @@ 1, argv, &retval); /* Cleanup */ - zval_ptr_dtor(&retval); + if(retval) + zval_ptr_dtor(&retval); } /* }}} */ @@ -1478,7 +1500,8 @@ 4, argv, &retval); /* Free up */ - zval_ptr_dtor(&retval); + if(retval) + zval_ptr_dtor(&retval); } else { char *errmsg = NULL; /* Error message */
--- sablot.c.old Sat May 11 12:10:49 2002 +++ sablot.c Sat May 11 12:58:18 2002 @@ -52,15 +52,15 @@ static int scheme_close(void *, SablotHandle, int); /* Sax handler functions */ -static SAX_RETURN sax_startdoc(void *); -static SAX_RETURN sax_startelement(void *, const char *, const char **); -static SAX_RETURN sax_endelement(void *, const char *); -static SAX_RETURN sax_startnamespace(void *, const char *, const char *); -static SAX_RETURN sax_endnamespace(void *, const char *); -static SAX_RETURN sax_comment(void *, const char *); -static SAX_RETURN sax_pi(void *, const char *, const char *); -static SAX_RETURN sax_characters(void *, const char *, int); -static SAX_RETURN sax_enddoc(void *); +static SAX_RETURN sax_startdoc(void *, SablotHandle); +static SAX_RETURN sax_startelement(void *, SablotHandle, const char *, const char **); +static SAX_RETURN sax_endelement(void *, SablotHandle, const char *); +static SAX_RETURN sax_startnamespace(void *, SablotHandle, const char *, const char *); +static SAX_RETURN sax_endnamespace(void *, SablotHandle, const char *); +static SAX_RETURN sax_comment(void *, SablotHandle, const char *); +static SAX_RETURN sax_pi(void *, SablotHandle, const char *, const char *); +static SAX_RETURN sax_characters(void *, SablotHandle, const char *, int); +static SAX_RETURN sax_enddoc(void *, SablotHandle); /* Error handlers */ static MH_ERROR error_makecode(void *, SablotHandle, int, unsigned short, unsigned short); @@ -723,12 +723,14 @@ xslt_call_function("scheme get all", XSLT_SCHEME(handle).get_all, 3, argv, &retval); - /* Save the return value in the buffer (copying it) */ - *buffer = estrndup(Z_STRVAL_P(retval), Z_STRLEN_P(retval)); - *byte_count = Z_STRLEN_P(retval); + if(retval) { + /* Save the return value in the buffer (copying it) */ + *buffer = estrndup(Z_STRVAL_P(retval), Z_STRLEN_P(retval)); + *byte_count = Z_STRLEN_P(retval); - /* Free return value */ - zval_ptr_dtor(&retval); + /* Free return value */ + zval_ptr_dtor(&retval); + } return 0; } @@ -801,11 +803,13 @@ xslt_call_function("scheme open", XSLT_SCHEME(handle).open, 3, argv, &retval); - /* Return value is a resource pointer to an open file */ - *fd = Z_LVAL_P(retval); + if(retval) { + /* Return value is a resource pointer to an open file */ + *fd = Z_LVAL_P(retval); - /* Free it all up */ - zval_ptr_dtor(&retval); + /* Free it all up */ + zval_ptr_dtor(&retval); + } /* return success */ return 0; @@ -845,11 +849,13 @@ xslt_call_function("scheme get", XSLT_SCHEME(handle).get, 3, argv, &retval); - /* Returns the number of bytes read */ - *byte_count = Z_LVAL_P(retval); + if(retval) { + /* Returns the number of bytes read */ + *byte_count = Z_LVAL_P(retval); - /* Free things up */ - zval_ptr_dtor(&retval); + /* Free things up */ + zval_ptr_dtor(&retval); + } /* return success */ return 0; @@ -889,11 +895,13 @@ xslt_call_function("scheme put", XSLT_SCHEME(handle).put, 3, argv, &retval); - /* The return value is the number of bytes written */ - *byte_count = Z_LVAL_P(retval); + if(retval) { + /* The return value is the number of bytes written */ + *byte_count = Z_LVAL_P(retval); - /* Free everything up */ - zval_ptr_dtor(&retval); + /* Free everything up */ + zval_ptr_dtor(&retval); + } /* Return success */ return 0; @@ -931,7 +939,8 @@ 2, argv, &retval); /* Free everything up */ - zval_ptr_dtor(&retval); + if(retval) + zval_ptr_dtor(&retval); /* Return success */ return 0; @@ -940,7 +949,7 @@ /* {{{ sax_startdoc() Called when the document starts to be processed */ -static SAX_RETURN sax_startdoc(void *ctx) +static SAX_RETURN sax_startdoc(void *ctx, SablotHandle proc) { zval *argv[1]; /* Arguments to the sax start doc function */ zval *retval; /* Return value from sax start doc function */ @@ -964,13 +973,15 @@ 1, argv, &retval); /* Cleanup */ - zval_ptr_dtor(&retval); + if(retval) + zval_ptr_dtor(&retval); } /* }}} */ /* {{{ sax_startelement() Called when an element is begun to be processed */ static SAX_RETURN sax_startelement(void *ctx, + SablotHandle proc, const char *name, const char **attr) { @@ -1012,13 +1023,14 @@ 3, argv, &retval); /* Cleanup */ - zval_ptr_dtor(&retval); + if(retval) + zval_ptr_dtor(&retval); } /* }}} */ /* {{{ xslt_sax_endelement() Called when an ending XML element is encountered */ -static SAX_RETURN sax_endelement(void *ctx, const char *name) +static SAX_RETURN sax_endelement(void *ctx, SablotHandle proc, const char *name) { zval *argv[2]; /* Arguments to the sax end element function */ zval *retval; /* Return value from the sax end element function */ @@ -1046,13 +1058,15 @@ 2, argv, &retval); /* Cleanup */ - zval_ptr_dtor(&retval); + if(retval) + zval_ptr_dtor(&retval); } /* }}} */ /* {{{ sax_startnamespace() Called at the beginning of the parsing of a new namespace */ -static SAX_RETURN sax_startnamespace(void *ctx, +static SAX_RETURN sax_startnamespace(void *ctx, + SablotHandle proc, const char *prefix, const char *uri) { @@ -1085,13 +1099,14 @@ 3, argv, &retval); /* Cleanup */ - zval_ptr_dtor(&retval); + if(retval) + zval_ptr_dtor(&retval); } /* }}} */ /* {{{ sax_endnamespace() Called when a new namespace is finished being parsed */ -static SAX_RETURN sax_endnamespace(void *ctx, const char *prefix) +static SAX_RETURN sax_endnamespace(void *ctx, SablotHandle proc, const char *prefix) { zval *argv[2]; /* Arguments to the sax end namespace function */ zval *retval; /* Return value from the sax end namespace function */ @@ -1119,13 +1134,14 @@ 2, argv, &retval); /* Cleanup */ - zval_ptr_dtor(&retval); + if(retval) + zval_ptr_dtor(&retval); } /* }}} */ /* {{{ sax_comment() Called when a comment is found */ -static SAX_RETURN sax_comment(void *ctx, const char *contents) +static SAX_RETURN sax_comment(void *ctx, SablotHandle proc, const char *contents) { zval *argv[2]; /* Arguments to the sax comment function */ zval *retval; /* Return value from the sax comment function */ @@ -1153,13 +1169,15 @@ 2, argv, &retval); /* Cleanup */ - zval_ptr_dtor(&retval); + if(retval) + zval_ptr_dtor(&retval); } /* }}} */ /* {{{ sax_pi() Called when processing instructions are found */ static SAX_RETURN sax_pi(void *ctx, + SablotHandle proc, const char *target, const char *contents) { @@ -1192,13 +1210,15 @@ 3, argv, &retval); /* Cleanup */ - zval_ptr_dtor(&retval); + if(retval) + zval_ptr_dtor(&retval); } /* }}} */ /* {{{ sax_characters() Called when characters are come upon */ static SAX_RETURN sax_characters(void *ctx, + SablotHandle proc, const char *contents, int length) { @@ -1228,13 +1248,14 @@ 2, argv, &retval); /* Cleanup */ - zval_ptr_dtor(&retval); + if(retval) + zval_ptr_dtor(&retval); } /* }}} */ /* {{{ sax_enddoc() Called when the document is finished being parsed */ -static SAX_RETURN sax_enddoc(void *ctx) +static SAX_RETURN sax_enddoc(void *ctx, SablotHandle proc) { zval *argv[1]; /* Arguments to the end document function */ zval *retval; /* Return value from the end document function */ @@ -1259,7 +1280,8 @@ 1, argv, &retval); /* Cleanup */ - zval_ptr_dtor(&retval); + if(retval) + zval_ptr_dtor(&retval); } /* }}} */ @@ -1478,7 +1500,8 @@ 4, argv, &retval); /* Free up */ - zval_ptr_dtor(&retval); + if(retval) + zval_ptr_dtor(&retval); } else { char *errmsg = NULL; /* Error message */