After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 53536 - SegFault if file is not an xml file.
SegFault if file is not an xml file.
Status: VERIFIED FIXED
Product: libxml
Classification: Deprecated
Component: general
unspecified
Other Linux
: Normal critical
: ---
Assigned To: Daniel Veillard
Daniel Veillard
Depends on:
Blocks:
 
 
Reported: 2001-04-24 14:47 UTC by jflecomte
Modified: 2009-08-15 18:40 UTC
See Also:
GNOME target: ---
GNOME version: ---



Description jflecomte 2001-04-24 14:47:19 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 !
Comment 1 Daniel Veillard 2001-04-24 15:26:54 UTC
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--;
    }
Comment 2 Daniel Veillard 2001-04-26 09:18:26 UTC
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
Comment 3 Daniel Veillard 2001-04-26 09:21:26 UTC
changing status to FIXED,

Daniel
Comment 4 Daniel Veillard 2001-05-04 10:36:45 UTC
shipped in 2.3.8

Daniel