Bug Summary

File:libxmlsec/unxlngi6.pro/misc/build/xmlsec1-1.2.14/src/parser.c
Location:line 318, column 5
Description:Value stored to 'ret' is never read

Annotated Source Code

1/**
2 * XML Security Library (http://www.aleksey.com/xmlsec).
3 *
4 * XML Parser transform and utility functions.
5 *
6 * This is free software; see Copyright file in the source
7 * distribution for preciese wording.
8 *
9 * Copyright (C) 2002-2003 Aleksey Sanin <aleksey@aleksey.com>
10 */
11#include "globals.h"
12
13#include <stdlib.h>
14#include <string.h>
15
16#include <libxml/tree.h>
17#include <libxml/parser.h>
18#include <libxml/parserInternals.h>
19
20#include <xmlsec/xmlsec.h>
21#include <xmlsec/xmltree.h>
22#include <xmlsec/keys.h>
23#include <xmlsec/transforms.h>
24#include <xmlsec/parser.h>
25#include <xmlsec/errors.h>
26
27/**************************************************************************
28 *
29 * Internal parser
30 *
31 *****************************************************************************/
32typedef struct _xmlSecParserCtx xmlSecParserCtx,
33 *xmlSecParserCtxPtr;
34struct _xmlSecParserCtx {
35 xmlParserCtxtPtr parserCtx;
36};
37
38/**************************************************************************
39 *
40 * XML Parser transform
41 *
42 * xmlSecParserCtx is located after xmlSecTransform
43 *
44 ***************************************************************************/
45#define xmlSecParserSize(sizeof(xmlSecTransform) + sizeof(xmlSecParserCtx)) \
46 (sizeof(xmlSecTransform) + sizeof(xmlSecParserCtx))
47#define xmlSecParserGetCtx(transform)(((((( ( (transform) ) ) != ((void*)0)) && (( ( (transform
) ) )->id != ((void*)0)) && (( ( (transform) ) )->
id->klassSize >= sizeof(xmlSecTransformKlass)) &&
(( ( (transform) ) )->id->objSize >= sizeof(xmlSecTransform
)) && (( ( (transform) ) )->id->name != ((void*
)0))) && ((( (transform) )->id->objSize) >= (
(sizeof(xmlSecTransform) + sizeof(xmlSecParserCtx)) )))) ? (
(xmlSecParserCtxPtr)(((unsigned char*)(transform)) + sizeof(xmlSecTransform
))) : (xmlSecParserCtxPtr)((void*)0))
\
48 ((xmlSecTransformCheckSize((transform), xmlSecParserSize)(((( ( (transform) ) ) != ((void*)0)) && (( ( (transform
) ) )->id != ((void*)0)) && (( ( (transform) ) )->
id->klassSize >= sizeof(xmlSecTransformKlass)) &&
(( ( (transform) ) )->id->objSize >= sizeof(xmlSecTransform
)) && (( ( (transform) ) )->id->name != ((void*
)0))) && ((( (transform) )->id->objSize) >= (
(sizeof(xmlSecTransform) + sizeof(xmlSecParserCtx)) )))
) ? \
49 ((xmlSecParserCtxPtr)(((xmlSecByteunsigned char*)(transform)) + sizeof(xmlSecTransform))) : \
50 (xmlSecParserCtxPtr)NULL((void*)0))
51
52static int xmlSecParserInitialize (xmlSecTransformPtr transform);
53static void xmlSecParserFinalize (xmlSecTransformPtr transform);
54static int xmlSecParserPushBin (xmlSecTransformPtr transform,
55 const xmlSecByteunsigned char* data,
56 xmlSecSizesize_t dataSize,
57 int final,
58 xmlSecTransformCtxPtr transformCtx);
59static int xmlSecParserPopXml (xmlSecTransformPtr transform,
60 xmlSecNodeSetPtr* nodes,
61 xmlSecTransformCtxPtr transformCtx);
62
63static xmlSecTransformKlass xmlSecParserKlass = {
64 /* klass/object sizes */
65 sizeof(xmlSecTransformKlass), /* xmlSecSize klassSize */
66 xmlSecParserSize(sizeof(xmlSecTransform) + sizeof(xmlSecParserCtx)), /* xmlSecSize objSize */
67
68 BAD_CAST(xmlChar *) "xml-parser", /* const xmlChar* name; */
69 NULL((void*)0), /* const xmlChar* href; */
70 xmlSecTransformUsageDSigTransform0x0001, /* xmlSecTransformUsage usage; */
71
72 xmlSecParserInitialize, /* xmlSecTransformInitializeMethod initialize; */
73 xmlSecParserFinalize, /* xmlSecTransformFinalizeMethod finalize; */
74 NULL((void*)0), /* xmlSecTransformNodeReadMethod readNode; */
75 NULL((void*)0), /* xmlSecTransformNodeWriteMethod writeNode; */
76 NULL((void*)0), /* xmlSecTransformSetKeyReqMethod setKeyReq; */
77 NULL((void*)0), /* xmlSecTransformSetKeyMethod setKey; */
78 NULL((void*)0), /* xmlSecTransformValidateMethod validate; */
79 xmlSecTransformDefaultGetDataType, /* xmlSecTransformGetDataTypeMethod getDataType; */
80 xmlSecParserPushBin, /* xmlSecTransformPushBinMethod pushBin; */
81 NULL((void*)0), /* xmlSecTransformPopBinMethod popBin; */
82 NULL((void*)0), /* xmlSecTransformPushXmlMethod pushXml; */
83 xmlSecParserPopXml, /* xmlSecTransformPopXmlMethod popXml; */
84 NULL((void*)0), /* xmlSecTransformExecuteMethod execute; */
85
86 NULL((void*)0), /* void* reserved0; */
87 NULL((void*)0), /* void* reserved1; */
88};
89
90/**
91 * xmlSecTransformXmlParserGetKlass:
92 *
93 * The XML parser transform.
94 *
95 * Returns: XML parser transform klass.
96 */
97xmlSecTransformId
98xmlSecTransformXmlParserGetKlass(void) {
99 return(&xmlSecParserKlass);
100}
101
102static int
103xmlSecParserInitialize(xmlSecTransformPtr transform) {
104 xmlSecParserCtxPtr ctx;
105
106 xmlSecAssert2(xmlSecTransformCheckId(transform, xmlSecTransformXmlParserId), -1)if(!( (((( ( transform ) ) != ((void*)0)) && (( ( transform
) )->id != ((void*)0)) && (( ( transform ) )->
id->klassSize >= sizeof(xmlSecTransformKlass)) &&
(( ( transform ) )->id->objSize >= sizeof(xmlSecTransform
)) && (( ( transform ) )->id->name != ((void*)0
))) && ((((const xmlSecTransformId) (( transform )->
id))) == ( xmlSecTransformXmlParserGetKlass() ))) ) ) { xmlSecError
("parser.c",106,__FUNCTION__, ((void*)0), "xmlSecTransformCheckId(transform, xmlSecTransformXmlParserId)"
, 100, " "); return(-1); }
;
107 xmlSecAssert2(xmlSecTransformCheckSize(transform, xmlSecParserSize), -1)if(!( (((( ( transform ) ) != ((void*)0)) && (( ( transform
) )->id != ((void*)0)) && (( ( transform ) )->
id->klassSize >= sizeof(xmlSecTransformKlass)) &&
(( ( transform ) )->id->objSize >= sizeof(xmlSecTransform
)) && (( ( transform ) )->id->name != ((void*)0
))) && ((( transform )->id->objSize) >= ( (sizeof
(xmlSecTransform) + sizeof(xmlSecParserCtx)) ))) ) ) { xmlSecError
("parser.c",107,__FUNCTION__, ((void*)0), "xmlSecTransformCheckSize(transform, xmlSecParserSize)"
, 100, " "); return(-1); }
;
108
109 ctx = xmlSecParserGetCtx(transform)(((((( ( (transform) ) ) != ((void*)0)) && (( ( (transform
) ) )->id != ((void*)0)) && (( ( (transform) ) )->
id->klassSize >= sizeof(xmlSecTransformKlass)) &&
(( ( (transform) ) )->id->objSize >= sizeof(xmlSecTransform
)) && (( ( (transform) ) )->id->name != ((void*
)0))) && ((( (transform) )->id->objSize) >= (
(sizeof(xmlSecTransform) + sizeof(xmlSecParserCtx)) )))) ? (
(xmlSecParserCtxPtr)(((unsigned char*)(transform)) + sizeof(xmlSecTransform
))) : (xmlSecParserCtxPtr)((void*)0))
;
110 xmlSecAssert2(ctx != NULL, -1)if(!( ctx != ((void*)0) ) ) { xmlSecError("parser.c",110,__FUNCTION__
, ((void*)0), "ctx != NULL", 100, " "); return(-1); }
;
111
112 /* initialize context */
113 memset(ctx, 0, sizeof(xmlSecParserCtx));
114 return(0);
115}
116
117static void
118xmlSecParserFinalize(xmlSecTransformPtr transform) {
119 xmlSecParserCtxPtr ctx;
120
121 xmlSecAssert(xmlSecTransformCheckId(transform, xmlSecTransformXmlParserId))if(!( (((( ( transform ) ) != ((void*)0)) && (( ( transform
) )->id != ((void*)0)) && (( ( transform ) )->
id->klassSize >= sizeof(xmlSecTransformKlass)) &&
(( ( transform ) )->id->objSize >= sizeof(xmlSecTransform
)) && (( ( transform ) )->id->name != ((void*)0
))) && ((((const xmlSecTransformId) (( transform )->
id))) == ( xmlSecTransformXmlParserGetKlass() ))) ) ) { xmlSecError
("parser.c",121,__FUNCTION__, ((void*)0), "xmlSecTransformCheckId(transform, xmlSecTransformXmlParserId)"
, 100, " "); return; }
;
122 xmlSecAssert(xmlSecTransformCheckSize(transform, xmlSecParserSize))if(!( (((( ( transform ) ) != ((void*)0)) && (( ( transform
) )->id != ((void*)0)) && (( ( transform ) )->
id->klassSize >= sizeof(xmlSecTransformKlass)) &&
(( ( transform ) )->id->objSize >= sizeof(xmlSecTransform
)) && (( ( transform ) )->id->name != ((void*)0
))) && ((( transform )->id->objSize) >= ( (sizeof
(xmlSecTransform) + sizeof(xmlSecParserCtx)) ))) ) ) { xmlSecError
("parser.c",122,__FUNCTION__, ((void*)0), "xmlSecTransformCheckSize(transform, xmlSecParserSize)"
, 100, " "); return; }
;
123
124 ctx = xmlSecParserGetCtx(transform)(((((( ( (transform) ) ) != ((void*)0)) && (( ( (transform
) ) )->id != ((void*)0)) && (( ( (transform) ) )->
id->klassSize >= sizeof(xmlSecTransformKlass)) &&
(( ( (transform) ) )->id->objSize >= sizeof(xmlSecTransform
)) && (( ( (transform) ) )->id->name != ((void*
)0))) && ((( (transform) )->id->objSize) >= (
(sizeof(xmlSecTransform) + sizeof(xmlSecParserCtx)) )))) ? (
(xmlSecParserCtxPtr)(((unsigned char*)(transform)) + sizeof(xmlSecTransform
))) : (xmlSecParserCtxPtr)((void*)0))
;
125 xmlSecAssert(ctx != NULL)if(!( ctx != ((void*)0) ) ) { xmlSecError("parser.c",125,__FUNCTION__
, ((void*)0), "ctx != NULL", 100, " "); return; }
;
126
127 if(ctx->parserCtx != NULL((void*)0)) {
128 xmlFreeParserCtxt(ctx->parserCtx);
129 }
130 memset(ctx, 0, sizeof(xmlSecParserCtx));
131}
132
133static int
134xmlSecParserPushBin(xmlSecTransformPtr transform, const xmlSecByteunsigned char* data,
135 xmlSecSizesize_t dataSize, int final, xmlSecTransformCtxPtr transformCtx) {
136 xmlSecParserCtxPtr ctx;
137 int ret;
138
139 xmlSecAssert2(xmlSecTransformCheckId(transform, xmlSecTransformXmlParserId), -1)if(!( (((( ( transform ) ) != ((void*)0)) && (( ( transform
) )->id != ((void*)0)) && (( ( transform ) )->
id->klassSize >= sizeof(xmlSecTransformKlass)) &&
(( ( transform ) )->id->objSize >= sizeof(xmlSecTransform
)) && (( ( transform ) )->id->name != ((void*)0
))) && ((((const xmlSecTransformId) (( transform )->
id))) == ( xmlSecTransformXmlParserGetKlass() ))) ) ) { xmlSecError
("parser.c",139,__FUNCTION__, ((void*)0), "xmlSecTransformCheckId(transform, xmlSecTransformXmlParserId)"
, 100, " "); return(-1); }
;
140 xmlSecAssert2(transformCtx != NULL, -1)if(!( transformCtx != ((void*)0) ) ) { xmlSecError("parser.c"
,140,__FUNCTION__, ((void*)0), "transformCtx != NULL", 100, " "
); return(-1); }
;
141
142 ctx = xmlSecParserGetCtx(transform)(((((( ( (transform) ) ) != ((void*)0)) && (( ( (transform
) ) )->id != ((void*)0)) && (( ( (transform) ) )->
id->klassSize >= sizeof(xmlSecTransformKlass)) &&
(( ( (transform) ) )->id->objSize >= sizeof(xmlSecTransform
)) && (( ( (transform) ) )->id->name != ((void*
)0))) && ((( (transform) )->id->objSize) >= (
(sizeof(xmlSecTransform) + sizeof(xmlSecParserCtx)) )))) ? (
(xmlSecParserCtxPtr)(((unsigned char*)(transform)) + sizeof(xmlSecTransform
))) : (xmlSecParserCtxPtr)((void*)0))
;
143 xmlSecAssert2(ctx != NULL, -1)if(!( ctx != ((void*)0) ) ) { xmlSecError("parser.c",143,__FUNCTION__
, ((void*)0), "ctx != NULL", 100, " "); return(-1); }
;
144
145 /* check/update current transform status */
146 if(transform->status == xmlSecTransformStatusNone) {
147 xmlSecAssert2(ctx->parserCtx == NULL, -1)if(!( ctx->parserCtx == ((void*)0) ) ) { xmlSecError("parser.c"
,147,__FUNCTION__, ((void*)0), "ctx->parserCtx == NULL", 100
, " "); return(-1); }
;
148
149 ctx->parserCtx = xmlCreatePushParserCtxt(NULL((void*)0), NULL((void*)0), NULL((void*)0), 0, NULL((void*)0));
150 if(ctx->parserCtx == NULL((void*)0)) {
151 xmlSecError(XMLSEC_ERRORS_HERE"parser.c",151,__FUNCTION__,
152 xmlSecErrorsSafeString(xmlSecTransformGetName(transform))(((((((( (transform) ) != ((void*)0)) && (( (transform
) )->id != ((void*)0)) && (( (transform) )->id->
klassSize >= sizeof(xmlSecTransformKlass)) && (( (
transform) )->id->objSize >= sizeof(xmlSecTransform)
) && (( (transform) )->id->name != ((void*)0)))
) ? ((((transform)->id)) ? (((transform)->id)->name)
: ((void*)0)) : ((void*)0))) != ((void*)0)) ? ((char*)((((((
(transform) ) != ((void*)0)) && (( (transform) )->
id != ((void*)0)) && (( (transform) )->id->klassSize
>= sizeof(xmlSecTransformKlass)) && (( (transform
) )->id->objSize >= sizeof(xmlSecTransform)) &&
(( (transform) )->id->name != ((void*)0)))) ? ((((transform
)->id)) ? (((transform)->id)->name) : ((void*)0)) : (
(void*)0)))) : (char*)"NULL")
,
153 "xmlCreatePushParserCtxt",
154 XMLSEC_ERRORS_R_XML_FAILED5,
155 XMLSEC_ERRORS_NO_MESSAGE" ");
156 return(-1);
157 }
158
159 /* required for c14n! */
160 ctx->parserCtx->loadsubset = XML_DETECT_IDS2 | XML_COMPLETE_ATTRS4;
161 ctx->parserCtx->replaceEntities = 1;
162
163 transform->status = xmlSecTransformStatusWorking;
164 } else if(transform->status == xmlSecTransformStatusFinished) {
165 return(0);
166 } else if(transform->status != xmlSecTransformStatusWorking) {
167 xmlSecError(XMLSEC_ERRORS_HERE"parser.c",167,__FUNCTION__,
168 xmlSecErrorsSafeString(xmlSecTransformGetName(transform))(((((((( (transform) ) != ((void*)0)) && (( (transform
) )->id != ((void*)0)) && (( (transform) )->id->
klassSize >= sizeof(xmlSecTransformKlass)) && (( (
transform) )->id->objSize >= sizeof(xmlSecTransform)
) && (( (transform) )->id->name != ((void*)0)))
) ? ((((transform)->id)) ? (((transform)->id)->name)
: ((void*)0)) : ((void*)0))) != ((void*)0)) ? ((char*)((((((
(transform) ) != ((void*)0)) && (( (transform) )->
id != ((void*)0)) && (( (transform) )->id->klassSize
>= sizeof(xmlSecTransformKlass)) && (( (transform
) )->id->objSize >= sizeof(xmlSecTransform)) &&
(( (transform) )->id->name != ((void*)0)))) ? ((((transform
)->id)) ? (((transform)->id)->name) : ((void*)0)) : (
(void*)0)))) : (char*)"NULL")
,
169 NULL((void*)0),
170 XMLSEC_ERRORS_R_INVALID_STATUS16,
171 "status=%d", transform->status);
172 return(-1);
173 }
174 xmlSecAssert2(transform->status == xmlSecTransformStatusWorking, -1)if(!( transform->status == xmlSecTransformStatusWorking ) )
{ xmlSecError("parser.c",174,__FUNCTION__, ((void*)0), "transform->status == xmlSecTransformStatusWorking"
, 100, " "); return(-1); }
;
175 xmlSecAssert2(ctx->parserCtx != NULL, -1)if(!( ctx->parserCtx != ((void*)0) ) ) { xmlSecError("parser.c"
,175,__FUNCTION__, ((void*)0), "ctx->parserCtx != NULL", 100
, " "); return(-1); }
;
176
177 /* push data to the input buffer */
178 if((data != NULL((void*)0)) && (dataSize > 0)) {
179 ret = xmlParseChunk(ctx->parserCtx, (const char*)data, dataSize, 0);
180 if(ret != 0) {
181 xmlSecError(XMLSEC_ERRORS_HERE"parser.c",181,__FUNCTION__,
182 xmlSecErrorsSafeString(xmlSecTransformGetName(transform))(((((((( (transform) ) != ((void*)0)) && (( (transform
) )->id != ((void*)0)) && (( (transform) )->id->
klassSize >= sizeof(xmlSecTransformKlass)) && (( (
transform) )->id->objSize >= sizeof(xmlSecTransform)
) && (( (transform) )->id->name != ((void*)0)))
) ? ((((transform)->id)) ? (((transform)->id)->name)
: ((void*)0)) : ((void*)0))) != ((void*)0)) ? ((char*)((((((
(transform) ) != ((void*)0)) && (( (transform) )->
id != ((void*)0)) && (( (transform) )->id->klassSize
>= sizeof(xmlSecTransformKlass)) && (( (transform
) )->id->objSize >= sizeof(xmlSecTransform)) &&
(( (transform) )->id->name != ((void*)0)))) ? ((((transform
)->id)) ? (((transform)->id)->name) : ((void*)0)) : (
(void*)0)))) : (char*)"NULL")
,
183 "xmlParseChunk",
184 XMLSEC_ERRORS_R_XML_FAILED5,
185 "size=%d", dataSize);
186 return(-1);
187 }
188 }
189
190 /* finish parsing and push to next in the chain */
191 if(final != 0) {
192 ret = xmlParseChunk(ctx->parserCtx, NULL((void*)0), 0, 1);
193 if((ret != 0) || (ctx->parserCtx->myDoc == NULL((void*)0))) {
194 xmlSecError(XMLSEC_ERRORS_HERE"parser.c",194,__FUNCTION__,
195 xmlSecErrorsSafeString(xmlSecTransformGetName(transform))(((((((( (transform) ) != ((void*)0)) && (( (transform
) )->id != ((void*)0)) && (( (transform) )->id->
klassSize >= sizeof(xmlSecTransformKlass)) && (( (
transform) )->id->objSize >= sizeof(xmlSecTransform)
) && (( (transform) )->id->name != ((void*)0)))
) ? ((((transform)->id)) ? (((transform)->id)->name)
: ((void*)0)) : ((void*)0))) != ((void*)0)) ? ((char*)((((((
(transform) ) != ((void*)0)) && (( (transform) )->
id != ((void*)0)) && (( (transform) )->id->klassSize
>= sizeof(xmlSecTransformKlass)) && (( (transform
) )->id->objSize >= sizeof(xmlSecTransform)) &&
(( (transform) )->id->name != ((void*)0)))) ? ((((transform
)->id)) ? (((transform)->id)->name) : ((void*)0)) : (
(void*)0)))) : (char*)"NULL")
,
196 "xmlParseChunk",
197 XMLSEC_ERRORS_R_XML_FAILED5,
198 XMLSEC_ERRORS_NO_MESSAGE" ");
199 return(-1);
200 }
201
202 /* todo: check that document is well formed? */
203 transform->outNodes = xmlSecNodeSetCreate(ctx->parserCtx->myDoc,
204 NULL((void*)0), xmlSecNodeSetTree);
205 if(transform->outNodes == NULL((void*)0)) {
206 xmlSecError(XMLSEC_ERRORS_HERE"parser.c",206,__FUNCTION__,
207 xmlSecErrorsSafeString(xmlSecTransformGetName(transform))(((((((( (transform) ) != ((void*)0)) && (( (transform
) )->id != ((void*)0)) && (( (transform) )->id->
klassSize >= sizeof(xmlSecTransformKlass)) && (( (
transform) )->id->objSize >= sizeof(xmlSecTransform)
) && (( (transform) )->id->name != ((void*)0)))
) ? ((((transform)->id)) ? (((transform)->id)->name)
: ((void*)0)) : ((void*)0))) != ((void*)0)) ? ((char*)((((((
(transform) ) != ((void*)0)) && (( (transform) )->
id != ((void*)0)) && (( (transform) )->id->klassSize
>= sizeof(xmlSecTransformKlass)) && (( (transform
) )->id->objSize >= sizeof(xmlSecTransform)) &&
(( (transform) )->id->name != ((void*)0)))) ? ((((transform
)->id)) ? (((transform)->id)->name) : ((void*)0)) : (
(void*)0)))) : (char*)"NULL")
,
208 "xmlSecNodeSetCreate",
209 XMLSEC_ERRORS_R_XMLSEC_FAILED1,
210 XMLSEC_ERRORS_NO_MESSAGE" ");
211 xmlFreeDoc(ctx->parserCtx->myDoc);
212 ctx->parserCtx->myDoc = NULL((void*)0);
213 return(-1);
214 }
215 xmlSecNodeSetDocDestroy(transform->outNodes); /* this node set "owns" the doc pointer */
216 ctx->parserCtx->myDoc = NULL((void*)0);
217
218 /* push result to the next transform (if exist) */
219 if(transform->next != NULL((void*)0)) {
220 ret = xmlSecTransformPushXml(transform->next, transform->outNodes, transformCtx);
221 if(ret < 0) {
222 xmlSecError(XMLSEC_ERRORS_HERE"parser.c",222,__FUNCTION__,
223 xmlSecErrorsSafeString(xmlSecTransformGetName(transform))(((((((( (transform) ) != ((void*)0)) && (( (transform
) )->id != ((void*)0)) && (( (transform) )->id->
klassSize >= sizeof(xmlSecTransformKlass)) && (( (
transform) )->id->objSize >= sizeof(xmlSecTransform)
) && (( (transform) )->id->name != ((void*)0)))
) ? ((((transform)->id)) ? (((transform)->id)->name)
: ((void*)0)) : ((void*)0))) != ((void*)0)) ? ((char*)((((((
(transform) ) != ((void*)0)) && (( (transform) )->
id != ((void*)0)) && (( (transform) )->id->klassSize
>= sizeof(xmlSecTransformKlass)) && (( (transform
) )->id->objSize >= sizeof(xmlSecTransform)) &&
(( (transform) )->id->name != ((void*)0)))) ? ((((transform
)->id)) ? (((transform)->id)->name) : ((void*)0)) : (
(void*)0)))) : (char*)"NULL")
,
224 "xmlSecTransformPushXml",
225 XMLSEC_ERRORS_R_XMLSEC_FAILED1,
226 XMLSEC_ERRORS_NO_MESSAGE" ");
227 return(-1);
228 }
229 }
230
231 transform->status = xmlSecTransformStatusFinished;
232 }
233
234 return(0);
235}
236
237static int
238xmlSecParserPopXml(xmlSecTransformPtr transform, xmlSecNodeSetPtr* nodes,
239 xmlSecTransformCtxPtr transformCtx) {
240 xmlSecParserCtxPtr ctx;
241 xmlParserInputBufferPtr buf;
242 xmlParserInputPtr input;
243 xmlParserCtxtPtr ctxt;
244 xmlDocPtr doc;
245 int ret;
246
247 xmlSecAssert2(xmlSecTransformCheckId(transform, xmlSecTransformXmlParserId), -1)if(!( (((( ( transform ) ) != ((void*)0)) && (( ( transform
) )->id != ((void*)0)) && (( ( transform ) )->
id->klassSize >= sizeof(xmlSecTransformKlass)) &&
(( ( transform ) )->id->objSize >= sizeof(xmlSecTransform
)) && (( ( transform ) )->id->name != ((void*)0
))) && ((((const xmlSecTransformId) (( transform )->
id))) == ( xmlSecTransformXmlParserGetKlass() ))) ) ) { xmlSecError
("parser.c",247,__FUNCTION__, ((void*)0), "xmlSecTransformCheckId(transform, xmlSecTransformXmlParserId)"
, 100, " "); return(-1); }
;
248 xmlSecAssert2(nodes != NULL, -1)if(!( nodes != ((void*)0) ) ) { xmlSecError("parser.c",248,__FUNCTION__
, ((void*)0), "nodes != NULL", 100, " "); return(-1); }
;
249 xmlSecAssert2(transformCtx != NULL, -1)if(!( transformCtx != ((void*)0) ) ) { xmlSecError("parser.c"
,249,__FUNCTION__, ((void*)0), "transformCtx != NULL", 100, " "
); return(-1); }
;
250
251 ctx = xmlSecParserGetCtx(transform)(((((( ( (transform) ) ) != ((void*)0)) && (( ( (transform
) ) )->id != ((void*)0)) && (( ( (transform) ) )->
id->klassSize >= sizeof(xmlSecTransformKlass)) &&
(( ( (transform) ) )->id->objSize >= sizeof(xmlSecTransform
)) && (( ( (transform) ) )->id->name != ((void*
)0))) && ((( (transform) )->id->objSize) >= (
(sizeof(xmlSecTransform) + sizeof(xmlSecParserCtx)) )))) ? (
(xmlSecParserCtxPtr)(((unsigned char*)(transform)) + sizeof(xmlSecTransform
))) : (xmlSecParserCtxPtr)((void*)0))
;
252 xmlSecAssert2(ctx != NULL, -1)if(!( ctx != ((void*)0) ) ) { xmlSecError("parser.c",252,__FUNCTION__
, ((void*)0), "ctx != NULL", 100, " "); return(-1); }
;
253
254 /* check/update current transform status */
255 switch(transform->status) {
256 case xmlSecTransformStatusNone:
257 transform->status = xmlSecTransformStatusWorking;
258 break;
259 case xmlSecTransformStatusWorking:
260 /* just do nothing */
261 break;
262 case xmlSecTransformStatusFinished:
263 (*nodes) = NULL((void*)0);
264 return(0);
265 default:
266 xmlSecError(XMLSEC_ERRORS_HERE"parser.c",266,__FUNCTION__,
267 xmlSecErrorsSafeString(xmlSecTransformGetName(transform))(((((((( (transform) ) != ((void*)0)) && (( (transform
) )->id != ((void*)0)) && (( (transform) )->id->
klassSize >= sizeof(xmlSecTransformKlass)) && (( (
transform) )->id->objSize >= sizeof(xmlSecTransform)
) && (( (transform) )->id->name != ((void*)0)))
) ? ((((transform)->id)) ? (((transform)->id)->name)
: ((void*)0)) : ((void*)0))) != ((void*)0)) ? ((char*)((((((
(transform) ) != ((void*)0)) && (( (transform) )->
id != ((void*)0)) && (( (transform) )->id->klassSize
>= sizeof(xmlSecTransformKlass)) && (( (transform
) )->id->objSize >= sizeof(xmlSecTransform)) &&
(( (transform) )->id->name != ((void*)0)))) ? ((((transform
)->id)) ? (((transform)->id)->name) : ((void*)0)) : (
(void*)0)))) : (char*)"NULL")
,
268 NULL((void*)0),
269 XMLSEC_ERRORS_R_INVALID_STATUS16,
270 "status=%d", transform->status);
271 return(-1);
272 }
273 xmlSecAssert2(transform->status == xmlSecTransformStatusWorking, -1)if(!( transform->status == xmlSecTransformStatusWorking ) )
{ xmlSecError("parser.c",273,__FUNCTION__, ((void*)0), "transform->status == xmlSecTransformStatusWorking"
, 100, " "); return(-1); }
;
274
275 /* prepare parser context */
276 if(transform->prev == NULL((void*)0)) {
277 xmlSecError(XMLSEC_ERRORS_HERE"parser.c",277,__FUNCTION__,
278 xmlSecErrorsSafeString(xmlSecTransformGetName(transform))(((((((( (transform) ) != ((void*)0)) && (( (transform
) )->id != ((void*)0)) && (( (transform) )->id->
klassSize >= sizeof(xmlSecTransformKlass)) && (( (
transform) )->id->objSize >= sizeof(xmlSecTransform)
) && (( (transform) )->id->name != ((void*)0)))
) ? ((((transform)->id)) ? (((transform)->id)->name)
: ((void*)0)) : ((void*)0))) != ((void*)0)) ? ((char*)((((((
(transform) ) != ((void*)0)) && (( (transform) )->
id != ((void*)0)) && (( (transform) )->id->klassSize
>= sizeof(xmlSecTransformKlass)) && (( (transform
) )->id->objSize >= sizeof(xmlSecTransform)) &&
(( (transform) )->id->name != ((void*)0)))) ? ((((transform
)->id)) ? (((transform)->id)->name) : ((void*)0)) : (
(void*)0)))) : (char*)"NULL")
,
279 NULL((void*)0),
280 XMLSEC_ERRORS_R_INVALID_TRANSFORM31,
281 "prev transform is null");
282 return(-1);
283 }
284
285 buf = xmlSecTransformCreateInputBuffer(transform->prev, transformCtx);
286 if(buf == NULL((void*)0)) {
287 xmlSecError(XMLSEC_ERRORS_HERE"parser.c",287,__FUNCTION__,
288 xmlSecErrorsSafeString(xmlSecTransformGetName(transform))(((((((( (transform) ) != ((void*)0)) && (( (transform
) )->id != ((void*)0)) && (( (transform) )->id->
klassSize >= sizeof(xmlSecTransformKlass)) && (( (
transform) )->id->objSize >= sizeof(xmlSecTransform)
) && (( (transform) )->id->name != ((void*)0)))
) ? ((((transform)->id)) ? (((transform)->id)->name)
: ((void*)0)) : ((void*)0))) != ((void*)0)) ? ((char*)((((((
(transform) ) != ((void*)0)) && (( (transform) )->
id != ((void*)0)) && (( (transform) )->id->klassSize
>= sizeof(xmlSecTransformKlass)) && (( (transform
) )->id->objSize >= sizeof(xmlSecTransform)) &&
(( (transform) )->id->name != ((void*)0)))) ? ((((transform
)->id)) ? (((transform)->id)->name) : ((void*)0)) : (
(void*)0)))) : (char*)"NULL")
,
289 "xmlSecTransformCreateInputBuffer",
290 XMLSEC_ERRORS_R_XMLSEC_FAILED1,
291 XMLSEC_ERRORS_NO_MESSAGE" ");
292 return(-1);
293 }
294
295 ctxt = xmlNewParserCtxt();
296 if (ctxt == NULL((void*)0)) {
297 xmlSecError(XMLSEC_ERRORS_HERE"parser.c",297,__FUNCTION__,
298 xmlSecErrorsSafeString(xmlSecTransformGetName(transform))(((((((( (transform) ) != ((void*)0)) && (( (transform
) )->id != ((void*)0)) && (( (transform) )->id->
klassSize >= sizeof(xmlSecTransformKlass)) && (( (
transform) )->id->objSize >= sizeof(xmlSecTransform)
) && (( (transform) )->id->name != ((void*)0)))
) ? ((((transform)->id)) ? (((transform)->id)->name)
: ((void*)0)) : ((void*)0))) != ((void*)0)) ? ((char*)((((((
(transform) ) != ((void*)0)) && (( (transform) )->
id != ((void*)0)) && (( (transform) )->id->klassSize
>= sizeof(xmlSecTransformKlass)) && (( (transform
) )->id->objSize >= sizeof(xmlSecTransform)) &&
(( (transform) )->id->name != ((void*)0)))) ? ((((transform
)->id)) ? (((transform)->id)->name) : ((void*)0)) : (
(void*)0)))) : (char*)"NULL")
,
299 "xmlNewParserCtxt",
300 XMLSEC_ERRORS_R_XML_FAILED5,
301 XMLSEC_ERRORS_NO_MESSAGE" ");
302 xmlFreeParserInputBuffer(buf);
303 return(-1);
304 }
305
306 input = xmlNewIOInputStream(ctxt, buf, XML_CHAR_ENCODING_NONE);
307 if(input == NULL((void*)0)) {
308 xmlSecError(XMLSEC_ERRORS_HERE"parser.c",308,__FUNCTION__,
309 xmlSecErrorsSafeString(xmlSecTransformGetName(transform))(((((((( (transform) ) != ((void*)0)) && (( (transform
) )->id != ((void*)0)) && (( (transform) )->id->
klassSize >= sizeof(xmlSecTransformKlass)) && (( (
transform) )->id->objSize >= sizeof(xmlSecTransform)
) && (( (transform) )->id->name != ((void*)0)))
) ? ((((transform)->id)) ? (((transform)->id)->name)
: ((void*)0)) : ((void*)0))) != ((void*)0)) ? ((char*)((((((
(transform) ) != ((void*)0)) && (( (transform) )->
id != ((void*)0)) && (( (transform) )->id->klassSize
>= sizeof(xmlSecTransformKlass)) && (( (transform
) )->id->objSize >= sizeof(xmlSecTransform)) &&
(( (transform) )->id->name != ((void*)0)))) ? ((((transform
)->id)) ? (((transform)->id)->name) : ((void*)0)) : (
(void*)0)))) : (char*)"NULL")
,
310 "xmlNewParserCtxt",
311 XMLSEC_ERRORS_R_XML_FAILED5,
312 XMLSEC_ERRORS_NO_MESSAGE" ");
313 xmlFreeParserCtxt(ctxt);
314 xmlFreeParserInputBuffer(buf);
315 return(-1);
316 }
317
318 ret = inputPush(ctxt, input);
Value stored to 'ret' is never read
319 if(input == NULL((void*)0)) {
320 xmlSecError(XMLSEC_ERRORS_HERE"parser.c",320,__FUNCTION__,
321 xmlSecErrorsSafeString(xmlSecTransformGetName(transform))(((((((( (transform) ) != ((void*)0)) && (( (transform
) )->id != ((void*)0)) && (( (transform) )->id->
klassSize >= sizeof(xmlSecTransformKlass)) && (( (
transform) )->id->objSize >= sizeof(xmlSecTransform)
) && (( (transform) )->id->name != ((void*)0)))
) ? ((((transform)->id)) ? (((transform)->id)->name)
: ((void*)0)) : ((void*)0))) != ((void*)0)) ? ((char*)((((((
(transform) ) != ((void*)0)) && (( (transform) )->
id != ((void*)0)) && (( (transform) )->id->klassSize
>= sizeof(xmlSecTransformKlass)) && (( (transform
) )->id->objSize >= sizeof(xmlSecTransform)) &&
(( (transform) )->id->name != ((void*)0)))) ? ((((transform
)->id)) ? (((transform)->id)->name) : ((void*)0)) : (
(void*)0)))) : (char*)"NULL")
,
322 "inputPush",
323 XMLSEC_ERRORS_R_XML_FAILED5,
324 XMLSEC_ERRORS_NO_MESSAGE" ");
325 xmlFreeInputStream(input);
326 xmlFreeParserCtxt(ctxt);
327 return(-1);
328 }
329
330 /* required for c14n! */
331 ctxt->loadsubset = XML_DETECT_IDS2 | XML_COMPLETE_ATTRS4;
332 ctxt->replaceEntities = 1;
333
334 /* finaly do the parsing */
335 ret = xmlParseDocument(ctxt);
336 if(ret < 0) {
337 xmlSecError(XMLSEC_ERRORS_HERE"parser.c",337,__FUNCTION__,
338 xmlSecErrorsSafeString(xmlSecTransformGetName(transform))(((((((( (transform) ) != ((void*)0)) && (( (transform
) )->id != ((void*)0)) && (( (transform) )->id->
klassSize >= sizeof(xmlSecTransformKlass)) && (( (
transform) )->id->objSize >= sizeof(xmlSecTransform)
) && (( (transform) )->id->name != ((void*)0)))
) ? ((((transform)->id)) ? (((transform)->id)->name)
: ((void*)0)) : ((void*)0))) != ((void*)0)) ? ((char*)((((((
(transform) ) != ((void*)0)) && (( (transform) )->
id != ((void*)0)) && (( (transform) )->id->klassSize
>= sizeof(xmlSecTransformKlass)) && (( (transform
) )->id->objSize >= sizeof(xmlSecTransform)) &&
(( (transform) )->id->name != ((void*)0)))) ? ((((transform
)->id)) ? (((transform)->id)->name) : ((void*)0)) : (
(void*)0)))) : (char*)"NULL")
,
339 "xmlParseDocument",
340 XMLSEC_ERRORS_R_XML_FAILED5,
341 XMLSEC_ERRORS_NO_MESSAGE" ");
342 if(ctxt->myDoc != NULL((void*)0)) {
343 xmlFreeDoc(ctxt->myDoc);
344 ctxt->myDoc = NULL((void*)0);
345 }
346 xmlFreeParserCtxt(ctxt);
347 return(-1);
348 }
349
350 /* remember the result and free parsing context */
351 doc = ctxt->myDoc;
352 ctxt->myDoc = NULL((void*)0);
353 xmlFreeParserCtxt(ctxt);
354
355 /* return result to the caller */
356 (*nodes) = xmlSecNodeSetCreate(doc, NULL((void*)0), xmlSecNodeSetTree);
357 if((*nodes) == NULL((void*)0)) {
358 xmlSecError(XMLSEC_ERRORS_HERE"parser.c",358,__FUNCTION__,
359 xmlSecErrorsSafeString(xmlSecTransformGetName(transform))(((((((( (transform) ) != ((void*)0)) && (( (transform
) )->id != ((void*)0)) && (( (transform) )->id->
klassSize >= sizeof(xmlSecTransformKlass)) && (( (
transform) )->id->objSize >= sizeof(xmlSecTransform)
) && (( (transform) )->id->name != ((void*)0)))
) ? ((((transform)->id)) ? (((transform)->id)->name)
: ((void*)0)) : ((void*)0))) != ((void*)0)) ? ((char*)((((((
(transform) ) != ((void*)0)) && (( (transform) )->
id != ((void*)0)) && (( (transform) )->id->klassSize
>= sizeof(xmlSecTransformKlass)) && (( (transform
) )->id->objSize >= sizeof(xmlSecTransform)) &&
(( (transform) )->id->name != ((void*)0)))) ? ((((transform
)->id)) ? (((transform)->id)->name) : ((void*)0)) : (
(void*)0)))) : (char*)"NULL")
,
360 "xmlSecNodeSetCreate",
361 XMLSEC_ERRORS_R_XMLSEC_FAILED1,
362 XMLSEC_ERRORS_NO_MESSAGE" ");
363 xmlFreeDoc(doc);
364 return(-1);
365 }
366 xmlSecNodeSetDocDestroy((*nodes)); /* this node set "owns" the doc pointer */
367 transform->status = xmlSecTransformStatusFinished;
368 return(0);
369}
370
371/**************************************************************************
372 *
373 * XML Parser functions
374 *
375 *************************************************************************/
376typedef struct _xmlSecExtMemoryParserCtx {
377 const xmlSecByteunsigned char *prefix;
378 xmlSecSizesize_t prefixSize;
379 const xmlSecByteunsigned char *buffer;
380 xmlSecSizesize_t bufferSize;
381 const xmlSecByteunsigned char *postfix;
382 xmlSecSizesize_t postfixSize;
383} xmlSecExtMemoryParserCtx, *xmlSecExtMemoryParserCtxPtr;
384
385/**
386 * xmlSecParseFile:
387 * @filename: the filename.
388 *
389 * Loads XML Doc from file @filename. We need a special version because of
390 * c14n issue. The code is copied from xmlSAXParseFileWithData() function.
391 *
392 * Returns: pointer to the loaded XML document or NULL if an error occurs.
393 */
394xmlDocPtr
395xmlSecParseFile(const char *filename) {
396 xmlDocPtr ret;
397 xmlParserCtxtPtr ctxt;
398 char *directory = NULL((void*)0);
399
400 xmlSecAssert2(filename != NULL, NULL)if(!( filename != ((void*)0) ) ) { xmlSecError("parser.c",400
,__FUNCTION__, ((void*)0), "filename != NULL", 100, " "); return
(((void*)0)); }
;
401
402 xmlInitParser();
403 ctxt = xmlCreateFileParserCtxt(filename);
404 if (ctxt == NULL((void*)0)) {
405 return(NULL((void*)0));
406 }
407
408 /* todo: set directories from current doc? */
409 if ((ctxt->directory == NULL((void*)0)) && (directory == NULL((void*)0)))
410 directory = xmlParserGetDirectory(filename);
411 if ((ctxt->directory == NULL((void*)0)) && (directory != NULL((void*)0)))
412 ctxt->directory = (char *) xmlStrdup((xmlChar *) directory);
413
414 /* required for c14n! */
415 ctxt->loadsubset = XML_DETECT_IDS2 | XML_COMPLETE_ATTRS4;
416 ctxt->replaceEntities = 1;
417
418 xmlParseDocument(ctxt);
419
420 if(ctxt->wellFormed) {
421 ret = ctxt->myDoc;
422 } else {
423 ret = NULL((void*)0);
424 xmlFreeDoc(ctxt->myDoc);
425 ctxt->myDoc = NULL((void*)0);
426 }
427 xmlFreeParserCtxt(ctxt);
428 return(ret);
429
430}
431
432/**
433 * xmlSecParseMemoryExt:
434 * @prefix: the first part of the input.
435 * @prefixSize: the size of the first part of the input.
436 * @buffer: the second part of the input.
437 * @bufferSize: the size of the second part of the input.
438 * @postfix: the third part of the input.
439 * @postfixSize: the size of the third part of the input.
440 *
441 * Loads XML Doc from 3 chunks of memory: @prefix, @buffer and @postfix.
442 *
443 * Returns: pointer to the loaded XML document or NULL if an error occurs.
444 */
445xmlDocPtr
446xmlSecParseMemoryExt(const xmlSecByteunsigned char *prefix, xmlSecSizesize_t prefixSize,
447 const xmlSecByteunsigned char *buffer, xmlSecSizesize_t bufferSize,
448 const xmlSecByteunsigned char *postfix, xmlSecSizesize_t postfixSize) {
449 xmlParserCtxtPtr ctxt = NULL((void*)0);
450 xmlDocPtr doc = NULL((void*)0);
451 int ret;
452
453 /* create context */
454 ctxt = xmlCreatePushParserCtxt(NULL((void*)0), NULL((void*)0), NULL((void*)0), 0, NULL((void*)0));
455 if(ctxt == NULL((void*)0)) {
456 xmlSecError(XMLSEC_ERRORS_HERE"parser.c",456,__FUNCTION__,
457 NULL((void*)0),
458 "xmlCreatePushParserCtxt",
459 XMLSEC_ERRORS_R_XML_FAILED5,
460 XMLSEC_ERRORS_NO_MESSAGE" ");
461 goto done;
462 }
463
464 /* required for c14n! */
465 ctxt->loadsubset = XML_DETECT_IDS2 | XML_COMPLETE_ATTRS4;
466 ctxt->replaceEntities = 1;
467
468 /* prefix */
469 if((prefix != NULL((void*)0)) && (prefixSize > 0)) {
470 ret = xmlParseChunk(ctxt, (const char*)prefix, prefixSize, 0);
471 if(ret != 0) {
472 xmlSecError(XMLSEC_ERRORS_HERE"parser.c",472,__FUNCTION__,
473 NULL((void*)0),
474 "xmlParseChunk",
475 XMLSEC_ERRORS_R_XML_FAILED5,
476 "prefixSize=%d", prefixSize);
477 goto done;
478 }
479 }
480
481 /* buffer */
482 if((buffer != NULL((void*)0)) && (bufferSize > 0)) {
483 ret = xmlParseChunk(ctxt, (const char*)buffer, bufferSize, 0);
484 if(ret != 0) {
485 xmlSecError(XMLSEC_ERRORS_HERE"parser.c",485,__FUNCTION__,
486 NULL((void*)0),
487 "xmlParseChunk",
488 XMLSEC_ERRORS_R_XML_FAILED5,
489 "bufferSize=%d", bufferSize);
490 goto done;
491 }
492 }
493
494 /* postfix */
495 if((postfix != NULL((void*)0)) && (postfixSize > 0)) {
496 ret = xmlParseChunk(ctxt, (const char*)postfix, postfixSize, 0);
497 if(ret != 0) {
498 xmlSecError(XMLSEC_ERRORS_HERE"parser.c",498,__FUNCTION__,
499 NULL((void*)0),
500 "xmlParseChunk",
501 XMLSEC_ERRORS_R_XML_FAILED5,
502 "postfixSize=%d", postfixSize);
503 goto done;
504 }
505 }
506
507 /* finishing */
508 ret = xmlParseChunk(ctxt, NULL((void*)0), 0, 1);
509 if((ret != 0) || (ctxt->myDoc == NULL((void*)0))) {
510 xmlSecError(XMLSEC_ERRORS_HERE"parser.c",510,__FUNCTION__,
511 NULL((void*)0),
512 "xmlParseChunk",
513 XMLSEC_ERRORS_R_XML_FAILED5,
514 XMLSEC_ERRORS_NO_MESSAGE" ");
515 goto done;
516 }
517 doc = ctxt->myDoc;
518
519done:
520 if(ctxt != NULL((void*)0)) {
521 xmlFreeParserCtxt(ctxt);
522 }
523 return(doc);
524}
525
526
527/**
528 * xmlSecParseMemory:
529 * @buffer: the input buffer.
530 * @size: the input buffer size.
531 * @recovery: the flag.
532 *
533 * Loads XML Doc from memory. We need a special version because of
534 * c14n issue. The code is copied from xmlSAXParseMemory() function.
535 *
536 * Returns: pointer to the loaded XML document or NULL if an error occurs.
537 */
538xmlDocPtr
539xmlSecParseMemory(const xmlSecByteunsigned char *buffer, xmlSecSizesize_t size, int recovery) {
540 xmlDocPtr ret;
541 xmlParserCtxtPtr ctxt;
542
543 xmlSecAssert2(buffer != NULL, NULL)if(!( buffer != ((void*)0) ) ) { xmlSecError("parser.c",543,__FUNCTION__
, ((void*)0), "buffer != NULL", 100, " "); return(((void*)0))
; }
;
544
545 ctxt = xmlCreateMemoryParserCtxt((char*)buffer, size);
546 if (ctxt == NULL((void*)0)) {
547 xmlSecError(XMLSEC_ERRORS_HERE"parser.c",547,__FUNCTION__,
548 NULL((void*)0),
549 "xmlCreateMemoryParserCtxt",
550 XMLSEC_ERRORS_R_XML_FAILED5,
551 XMLSEC_ERRORS_NO_MESSAGE" ");
552 return(NULL((void*)0));
553 }
554
555 /* required for c14n! */
556 ctxt->loadsubset = XML_DETECT_IDS2 | XML_COMPLETE_ATTRS4;
557 ctxt->replaceEntities = 1;
558
559 xmlParseDocument(ctxt);
560
561 if((ctxt->wellFormed) || recovery) {
562 ret = ctxt->myDoc;
563 } else {
564 ret = NULL((void*)0);
565 xmlFreeDoc(ctxt->myDoc);
566 ctxt->myDoc = NULL((void*)0);
567 }
568 xmlFreeParserCtxt(ctxt);
569 return(ret);
570}
571