<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=ISO-8859-1">
</head>
<body style="font-size: 10pt; font-family:Verdana,Arial">
<img style="margin-bottom:20px"
src="cid:part1.07040400.09070209@cardinal.hu" name="cardinal"
border="0">
<div>
Hi, <br>
I think I have found a bug in XPath/Xpath-Filter2 reference
evaluation. The bug is reproducable with the xmlsec command line
utility, using the attached input files.<br>
The problem is that the whole document is included in the
reference digest.<br>
<br>
The command line:<br>
xmlsec1 --sign --store-references --print-debug --id-attr:id
"urn:test.global":ToBeSigned --privkey-pem signkey.pem
--pubkey-cert-pem signcert.crt tobesigned.xml
<br>
<br>
After some debugging sessions I found, that the problem arises
when the libxml2 xpath evaluation returns an empty nodeset in the
form: the xmlXPathObject's type is XPATH_NODESET and the
nodesetval pointer is NULL. (Sometimes empty nodesets are
returned with a non-null nodesetval pointer, but
nodesetval->nodeNr=0)<br>
I have managed to correct the handlig of such empty nodesets by
two small modification:<br>
in nodeset.c: in function xmlSecNodeSetOneContains the default
value of the variable int in_nodes_set has to be set to 0:<br>
-------------------<br>
xmlSecNodeSetOneContains(xmlSecNodeSetPtr nset, xmlNodePtr node,
xmlNodePtr parent) {<br>
int in_nodes_set = 0;<br>
...<br>
-------------------<br>
By this NULL nodes pointers in xmlSecNodeSet nodesets are handled
correctly. But this arises another problem: when using an xpointer
in the corresponding reference,<br>
the initial xmlSecNodeSetPtr nodeset's nodes pointer is set to
NULL, with type xmlSecNodeSetNormal. This defines an empty
nodeset, so the initial nodeset has to be changed.<br>
In transforms.c in function xmlSecTransformCtxExecute has to be
created with type xmlSecNodeSetInvert instead of
xmlSecNodeSetNormal, which means the whole document:<br>
-------------------<br>
xmlSecTransformCtxExecute(xmlSecTransformCtxPtr ctx, xmlDocPtr
doc) {<br>
int ret;<br>
<br>
xmlSecAssert2(ctx != NULL, -1);<br>
xmlSecAssert2(ctx->result == NULL, -1);<br>
xmlSecAssert2(ctx->status == xmlSecTransformStatusNone,
-1);<br>
xmlSecAssert2(doc != NULL, -1);<br>
<br>
if((ctx->uri == NULL) || (xmlStrlen(ctx->uri) == 0)) {<br>
xmlSecNodeSetPtr nodes;<br>
<br>
if((ctx->xptrExpr != NULL) &&
(xmlStrlen(ctx->xptrExpr) > 0)){<br>
/* our xpointer transform takes care of providing
correct nodes set */<br>
nodes = xmlSecNodeSetCreate(doc, NULL,
xmlSecNodeSetInvert);<br>
...<br>
-------------------<br>
This way xpath evaluation seems correct. Of course my
modifications require more evaluation. <br>
<br>
<p style="color: rgb(4,31,91); margin-bottom:0px; margin-top:20px;
font-size: 10pt; font-weight: bold">Steingart Ferenc</p>
<p style="color: rgb(4,31,91); margin-top:1px; font-size: 8pt">fejlesztő,
programtervező matematikus<br>
Tel: 06 1 345 7974<br>
Email: <a class="moz-txt-link-abbreviated" href="mailto:steingart.ferenc@cardinal.hu">steingart.ferenc@cardinal.hu</a><br>
Web: <a href="http://www.cardinal.hu">http://www.cardinal.hu</a></p>
</div>
</body>
</html>