"A Fraser" <[EMAIL PROTECTED]> writes:

> How does one debug the HTML::Parser xs code? Do I need to rebuild the perl 
> binary with debugging enabled? I've tried building HTML::Parser itself with 
> OPTIMIZE=-g, and running gdb against perl (passing my program as a command 
> argument), and that doesn't seem to work.

I am not sure.  Having a -DDEBUGGING perl certainly works.

> The problem I am trying to debug is that HTML::Parser is causing perl to 
> segfault when presented with particularly braindead html. In this particular 
> case the html I am doing a parse_file on is clearly invalid (it is missing a 
> ">" on the second meta tag and is otherwise badly written), but the parser 
> probably shouldn't cause perl to segfault which is what it does on my 
> system. If you are interested in seeing the html file, grab it from 
> http://www.rameinc.com/ . I'm running the latest version of HTML::Parser and 
> LWP. I've tried it under both perl5.00503 and perl5.00404.

The problem was that we might reference freed memory at line 975 in
hparser.c if a start tag has lots of attributes.

The following patch ought to fix this problem.  I will also upload
HTML-Parser-3.08 with this fix later today.

Index: hparser.c
===================================================================
RCS file: /home/cvs/aas/perl/mods/html-parser/hparser.c,v
retrieving revision 2.41
retrieving revision 2.42
diff -u -p -u -r2.41 -r2.42
--- hparser.c   2000/03/20 12:17:38     2.41
+++ hparser.c   2000/05/23 10:44:59     2.42
@@ -1,4 +1,4 @@
-/* $Id: hparser.c,v 2.41 2000/03/20 12:17:38 gisle Exp $
+/* $Id: hparser.c,v 2.42 2000/05/23 10:44:59 gisle Exp $
  *
  * Copyright 1999-2000, Gisle Aas
  * Copyright 1999-2000, Michael A. Chase
@@ -966,7 +966,6 @@ parse_start(PSTATE* p_state, char *beg, 
     if (empty_tag)
       report_event(p_state, E_END, s, s, tokens, 1,
                   offset + (s - beg), self);
-    FREE_TOKENS;
 
     if (!p_state->xml_mode) {
       /* find out if this start tag should put us into literal_mode
@@ -998,6 +997,8 @@ parse_start(PSTATE* p_state, char *beg, 
     END_OF_LITERAL_SEARCH:
       ;
     }
+
+    FREE_TOKENS;
     return s;
   }
   
Regards,
Gisle

Reply via email to