GNOME Bugzilla – Bug 53536
SegFault if file is not an xml file.
Last modified: 2009-08-15 18:40:50 UTC
Hi, I wrote the following simple example: int main(int argc, char **argv) { xmlDocPtr doc ; xmlDoValidityCheckingDefaultValue = 1; printf("file :%s\n", argv[1] ); doc = xmlParseFile (argv[1]); return 0; } if the file i pass is not an xml file (a Makefile for example), i have a segfault. In valid.c in the xmlParserPrintFileContext procedure, if i comment the last loop while, i avoid this segfault. I'm not sure it's the right way !
Seems I can't reproduce it, what version are you using ? orchis:~/XML -> gcc -I . -L. -o tst tst.c .libs/libxml2.a -lz -lm orchis:~/XML -> ./tst Makefile file :Makefile Makefile:1: error: Start tag expected, '<' not found # Generated automatically from Makefile.in by configure. orchis:~/XML -> also xmlParserPrintFileContext() is not in valid.c but in error.c and i don't see hos this loop is segfaulting. Please provide more context I can't guess what is going wrong: xmlChar content[81]; xmlChar *ctnt; ... n = 0; ctnt = content; while ((n++ < 79) && (cur > base) && (*cur != '\n') && (*cur != '\r')) { *ctnt++ = ' '; cur--; }
On Wed, Apr 25, 2001 at 09:48:52AM +0200, Lecomte Jean François wrote: > Hi, > > I found what's wrong. If the first character of the file contains the > trouble, a '^' is inserted before the first char of the buffer content > One solution is in xmlParserPrintFileInfo (error.c) > > L142: > if(ctnt > content) > { > > *(--ctnt) = '^'; /*Could points beyond the first character*/ > *(++ctnt) = 0; > } > else > { > *ctnt = '^'; > *(++ctnt) = 0; > } > > And then everything is ok ! the description is fine, the patch is right, applied, bug considered fixed ! thanks a lot, Daniel
changing status to FIXED, Daniel
shipped in 2.3.8 Daniel