diff --git a/ChangeLog b/ChangeLog index 9c8217cd..680d6736 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +Mon Nov 8 12:55:16 CET 2004 Daniel Veillard + + * parser.c testapi.c xmlIO.c xmlstring.c: more fixes. + Mon Nov 8 11:24:57 CET 2004 Daniel Veillard * gentest.py testapi.c: more types, more coverage diff --git a/parser.c b/parser.c index 7399bfc0..05c31a96 100644 --- a/parser.c +++ b/parser.c @@ -9978,7 +9978,11 @@ xmlCreatePushParserCtxt(xmlSAXHandlerPtr sax, void *user_data, xmlFreeParserCtxt(ctxt); return(NULL); } - memcpy(ctxt->sax, sax, sizeof(xmlSAXHandler)); + memset(ctxt->sax, 0, sizeof(xmlSAXHandler)); + if (sax->initialized == XML_SAX2_MAGIC) + memcpy(ctxt->sax, sax, sizeof(xmlSAXHandler)); + else + memcpy(ctxt->sax, sax, sizeof(xmlSAXHandlerV1)); if (user_data != NULL) ctxt->userData = user_data; } @@ -10081,7 +10085,11 @@ xmlCreateIOParserCtxt(xmlSAXHandlerPtr sax, void *user_data, xmlFree(ctxt); return(NULL); } - memcpy(ctxt->sax, sax, sizeof(xmlSAXHandler)); + memset(ctxt->sax, 0, sizeof(xmlSAXHandler)); + if (sax->initialized == XML_SAX2_MAGIC) + memcpy(ctxt->sax, sax, sizeof(xmlSAXHandler)); + else + memcpy(ctxt->sax, sax, sizeof(xmlSAXHandlerV1)); if (user_data != NULL) ctxt->userData = user_data; } diff --git a/testapi.c b/testapi.c index 6708ce57..10a5dddf 100644 --- a/testapi.c +++ b/testapi.c @@ -20,7 +20,7 @@ static int generic_errors = 0; static int call_tests = 0; static int function_tests = 0; -static xmlChar chartab[1024] = " chartab\n"; +static xmlChar chartab[1024]; static int inttab[1024]; static unsigned long longtab[1024]; @@ -110,6 +110,11 @@ int main(int argc, char **argv) { int ret; int blocks, mem; + memset(chartab, 0, sizeof(chartab)); + strncpy(chartab, " chartab\n", 20); + memset(inttab, 0, sizeof(inttab)); + memset(longtab, 0, sizeof(longtab)); + xmlInitParser(); #ifdef LIBXML_SCHEMAS_ENABLED xmlRelaxNGInitTypes(); diff --git a/xmlIO.c b/xmlIO.c index 85281948..1ca80c95 100644 --- a/xmlIO.c +++ b/xmlIO.c @@ -420,7 +420,8 @@ __xmlLoaderErr(void *ctx, const char *msg, const char *filename) channel = ctxt->sax->warning; level = XML_ERR_WARNING; } - schannel = ctxt->sax->serror; + if (ctxt->sax->initialized == XML_SAX2_MAGIC) + schannel = ctxt->sax->serror; data = ctxt->userData; } __xmlRaiseError(schannel, channel, data, ctxt, NULL, XML_FROM_IO, @@ -1549,6 +1550,7 @@ xmlIOHTTPDfltOpenW( const char * post_uri ) { */ int xmlIOHTTPRead(void * context, char * buffer, int len) { + if ((buffer == NULL) || (len < 0)) return(-1); return(xmlNanoHTTPRead(context, &buffer[0], len)); } @@ -1827,6 +1829,7 @@ xmlIOFTPOpen (const char *filename) { */ int xmlIOFTPRead(void * context, char * buffer, int len) { + if ((buffer == NULL) || (len < 0)) return(-1); return(xmlNanoFTPRead(context, &buffer[0], len)); } diff --git a/xmlstring.c b/xmlstring.c index a4dc44c7..db94432c 100644 --- a/xmlstring.c +++ b/xmlstring.c @@ -92,8 +92,10 @@ xmlCharStrndup(const char *cur, int len) { xmlErrMemory(NULL, NULL); return(NULL); } - for (i = 0;i < len;i++) + for (i = 0;i < len;i++) { ret[i] = (xmlChar) cur[i]; + if (ret[i] == 0) return(ret); + } ret[len] = 0; return(ret); } @@ -809,6 +811,7 @@ xmlCheckUTF8(const unsigned char *utf) * @len: the number of characters in the array * * storage size of an UTF8 string + * the behaviour is not garanteed if the input string is not UTF-8 * * Returns the storage size of * the first 'len' characters of ARRAY @@ -829,8 +832,10 @@ xmlUTF8Strsize(const xmlChar *utf, int len) { if ( !*ptr ) break; if ( (ch = *ptr++) & 0x80) - while ( (ch<<=1) & 0x80 ) + while ((ch<<=1) & 0x80 ) { ptr++; + if (*ptr == 0) break; + } } return (ptr - utf); }