Re: [xml] bug in valid.c

Date view Thread view Subject view Author view

From: Gary Pennington (Gary.Pennington@uk.sun.com)
Date: Wed Feb 07 2001 - 15:45:13 EST


Hi Daniel,

I think that I may have found another problem in valid.c.

My fix isn't working, which makes me wonder why. Some debugging and
investigating got me looking at xmlAddRef and it seems to be fairly wrong to
me.

Near the end of the function, there is the following section of code :-

    /*
     * !!! Should we keep track of all refs ? and use xmlHashAddEntry2 ?
     */

    if (xmlHashAddEntry(table, value, ret) < 0) {
        xmlFreeRef(ret);
        return(NULL);
    }

When this code is executed any IDREF(S) which reference an ID multiple times
(probably from different elements, but in the case of IDREFS not
necessarily), then the add to the hash table will fail. Thus a document will
be reported as invalid because more than one element references an ID.

I took a hint from the comment and tried to fix the creation/update/access of
refs using xmlHashAddEntry/UpdateEntry/Lookup2 - but this really broke my
code and I was getting SIGSEGVs.

So, I thought about this and decided that as long as there is an entry in the
ref table for a ref, it doesn't matter if all refs are tracked or not. The
only function broken by this would be the xmlGetRef function, which isn't
actually used anywhere as far as I can tell.

So my patch to get my earlier patch working is to simply add a ref and ignore
failed adds since that means there is already a ref in the ref table.

Patch is :-

*** ../ORIG/libxml2-2.2.11/valid.c Fri Jan 5 06:39:29 2001
--- valid.c Wed Feb 7 20:38:23 2001
***************
*** 1774,1783 ****
      /*
       * !!! Should we keep track of all refs ? and use xmlHashAddEntry2 ?
       */
! if (xmlHashAddEntry(table, value, ret) < 0) {
! xmlFreeRef(ret);
! return(NULL);
! }
      return(ret);
  }

--- 1774,1781 ----
      /*
       * !!! Should we keep track of all refs ? and use xmlHashAddEntry2 ?
       */
!
! xmlHashAddEntry(table, value, ret);
      return(ret);
  }

I don't really like this fix, but I couldn't get the arity 2 version of the
hashtable logic to work, so I think this is good enough. I don't like the
fact that it breaks xmlGetRef, but having said that I'm not sure what the
point of xmlGetRef is anyway. Why would you want to get a single ref from a
document, wouldn't you want all of them as a navigable list?

Yours,

Gary

Daniel Veillard wrote:

> > I've found what I think is a bug in the xmlValidateOneAttribute
> > function. When checking for validity the routine does not detect that an
> > error has been flagged for a duplicate ID or non existent ref without
> > this patch. Thus invalid documents, although reported as such by the
> > error and warning functions, are not reported as invalid by the
> > xmlValidateDocument (etc... ) routines.
>
> Good catch !
> Right the error message is not sufficient :-\
>
> thanks, patched, will commit !
>
> Daniel
>
> --
> Daniel Veillard | Red Hat Network http://redhat.com/products/network/
> veillard@redhat.com | libxml Gnome XML toolkit http://xmlsoft.org/
> http://veillard.com/ | Rpmfind RPM search engine http://rpmfind.net/
> ----
> Message from the list xml@rpmfind.net
> Archived at : http://xmlsoft.org/messages/
> to unsubscribe: echo "unsubscribe xml" | mail majordomo@rpmfind.net

----
Message from the list xml@rpmfind.net
Archived at : http://xmlsoft.org/messages/
to unsubscribe: echo "unsubscribe xml" | mail  majordomo@rpmfind.net


Date view Thread view Subject view Author view

This archive was generated by hypermail 2b29 : Wed Feb 07 2001 - 16:44:01 EST