Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit110ebff

Browse files
committed
Fix some more bugs in contrib/xml2's xslt_process().
It failed to check for error return from xsltApplyStylesheet(), as reportedby Peter Gagarinov. (So far as I can tell, libxslt provides no convenientway to get a useful error message in failure cases. There might be someinconvenient way, but considering that this code is deprecated it's hard toget enthusiastic about putting lots of work into it. So I just made it say"failed to apply stylesheet", in line with the existing error checks.)While looking at the code I also noticed that the string returned byxsltSaveResultToString was never freed, resulting in a session-lifespanmemory leak.Back-patch to all supported versions.
1 parent3406861 commit110ebff

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

‎contrib/xml2/xslt_proc.c

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ xslt_process(PG_FUNCTION_ARGS)
5656

5757
text*doct=PG_GETARG_TEXT_P(0);
5858
text*ssheet=PG_GETARG_TEXT_P(1);
59+
text*result;
5960
text*paramstr;
6061
constchar*params[MAXPARAMS+1];/* +1 for the terminator */
6162
xsltStylesheetPtrstylesheet=NULL;
@@ -116,6 +117,16 @@ xslt_process(PG_FUNCTION_ARGS)
116117
}
117118

118119
restree=xsltApplyStylesheet(stylesheet,doctree,params);
120+
121+
if (restree==NULL)
122+
{
123+
xsltFreeStylesheet(stylesheet);
124+
xmlFreeDoc(doctree);
125+
xsltCleanupGlobals();
126+
xml_ereport(ERROR,ERRCODE_EXTERNAL_ROUTINE_EXCEPTION,
127+
"failed to apply stylesheet");
128+
}
129+
119130
resstat=xsltSaveResultToString(&resstr,&reslen,restree,stylesheet);
120131

121132
xsltFreeStylesheet(stylesheet);
@@ -124,10 +135,16 @@ xslt_process(PG_FUNCTION_ARGS)
124135

125136
xsltCleanupGlobals();
126137

138+
/* XXX this is pretty dubious, really ought to throw error instead */
127139
if (resstat<0)
128140
PG_RETURN_NULL();
129141

130-
PG_RETURN_TEXT_P(cstring_to_text_with_len((char*)resstr,reslen));
142+
result=cstring_to_text_with_len((char*)resstr,reslen);
143+
144+
if (resstr)
145+
xmlFree(resstr);
146+
147+
PG_RETURN_TEXT_P(result);
131148
#else/* !USE_LIBXSLT */
132149

133150
ereport(ERROR,

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp