Re: [xml] small patch to c14n.c



Thanks a lot! I hate to say this but I just found one more bug. Please find
the diff attached.


Aleksey.




Daniel Veillard wrote:
On Thu, Mar 14, 2002 at 11:26:19PM -0800, Aleksey Sanin wrote:
Daniel,

While testing XMLDSig I found a small bug in c14n code I wrote
(the namespace nodes were processed slightly incorrect in one
particular case). Please find the fix in attached diff.

Sure, done ! I also added C14N in the list of supported specifications
on the web page.

Also thanks for taking care of few other bugs I made in this code.
You know that it is very difficult to test all possible
options/compilers/platforms.

No problem. The only thing missing is the integration of your test suite
it's basically just adding the commands to the Makefile.am dumping them
in the test/ and result/ trees. I will try to do this before the next
release.

Daniel


Index: c14n.c
===================================================================
RCS file: /cvs/gnome/gnome-xml/c14n.c,v
retrieving revision 1.3
diff -c -r1.3 c14n.c
*** c14n.c      2002/03/11 09:15:30     1.3
--- c14n.c      2002/03/15 09:57:12
***************
*** 266,273 ****
      xmlNsPtr ns;
      xmlListPtr list;
      xmlNodePtr visible_parent;
      xmlNsPtr prev;
! 
      if ((ctx == NULL) || (cur == NULL) || (cur->type != XML_ELEMENT_NODE)) {
  #ifdef DEBUG_C14N
          xmlGenericError(xmlGenericErrorContext,
--- 266,274 ----
      xmlNsPtr ns;
      xmlListPtr list;
      xmlNodePtr visible_parent;
+     xmlNodePtr node;
      xmlNsPtr prev;
!     
      if ((ctx == NULL) || (cur == NULL) || (cur->type != XML_ELEMENT_NODE)) {
  #ifdef DEBUG_C14N
          xmlGenericError(xmlGenericErrorContext,
***************
*** 302,307 ****
--- 303,309 ----
       * defined in node parents). By this we need to now walk thru 
       * all namespace in current node and all invisible ancesstors
       */
+     node = cur;
      while (cur != visible_parent) {
          for (ns = cur->nsDef; ns != NULL; ns = ns->next) {
              /* 
***************
*** 311,316 ****
--- 313,323 ----
              if ((xmlC14NIsXmlNs(ns)) || (xmlListSearch(list, ns) != NULL)) {
                  continue;
              }
+           prev = xmlSearchNs(ctx->doc, node, ns->prefix);
+           if(prev != ns) {
+               /* we already processed a namespace with this name */
+               continue;
+           }
  
              /*
               * Lookup nearest namespace after visible parent having
***************
*** 780,785 ****
--- 787,793 ----
  {
      int ret;
      int ns_rendered_pos = 0;
+     int parent_is_doc = 0;
  
      if ((ctx == NULL) || (cur == NULL) || (cur->type != XML_ELEMENT_NODE)) {
  #ifdef DEBUG_C14N
***************
*** 811,818 ****
          ns_rendered_pos = ctx->ns_rendered->nodeNr;
      }
  
!     if (visible) {
          if (ctx->parent_is_doc) {
              ctx->pos = XMLC14N_INSIDE_DOCUMENT_ELEMENT;
          }
          xmlOutputBufferWriteString(ctx->buf, "<");
--- 819,829 ----
          ns_rendered_pos = ctx->ns_rendered->nodeNr;
      }
  
!     if (visible) {    
          if (ctx->parent_is_doc) {
+           /* save this flag into the stack */
+           parent_is_doc = ctx->parent_is_doc;
+           ctx->parent_is_doc = 0;
              ctx->pos = XMLC14N_INSIDE_DOCUMENT_ELEMENT;
          }
          xmlOutputBufferWriteString(ctx->buf, "<");
***************
*** 867,874 ****
          }
          xmlOutputBufferWriteString(ctx->buf, (const char *) cur->name);
          xmlOutputBufferWriteString(ctx->buf, ">");
!         if (ctx->parent_is_doc) {
!             ctx->pos = XMLC14N_AFTER_DOCUMENT_ELEMENT;
          }
      }
  
--- 878,887 ----
          }
          xmlOutputBufferWriteString(ctx->buf, (const char *) cur->name);
          xmlOutputBufferWriteString(ctx->buf, ">");
!         if (parent_is_doc) {
!           /* restore this flag from the stack for next node */
!             ctx->parent_is_doc = parent_is_doc;
!           ctx->pos = XMLC14N_AFTER_DOCUMENT_ELEMENT;
          }
      }
  


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]