Skip to content

Commit e7370ba

Browse files
committed
Fix xslt_process() to ensure that it inserts a NULL terminator after the
last pair of parameter name/value strings, even when there are MAXPARAMS of them. Aboriginal bug in contrib/xml2, noted while studying bug #4912 (though I'm not sure whether there's something else involved in that report). This might be thought a security issue, since it's a potential backend crash; but considering that untrustworthy users shouldn't be allowed to get their hands on xslt_process() anyway, it's probably not worth getting excited about.
1 parent b11ce56 commit e7370ba

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

contrib/xml2/xslt_proc.c

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* $PostgreSQL: pgsql/contrib/xml2/xslt_proc.c,v 1.15 2009/06/11 14:48:53 momjian Exp $
2+
* $PostgreSQL: pgsql/contrib/xml2/xslt_proc.c,v 1.16 2009/07/10 00:32:00 tgl Exp $
33
*
44
* XSLT processing functions (requiring libxslt)
55
*
@@ -38,7 +38,8 @@ static void parse_params(const char **params, text *paramstr);
3838
Datum xslt_process(PG_FUNCTION_ARGS);
3939

4040

41-
#define MAXPARAMS 20
41+
#define MAXPARAMS 20 /* must be even, see parse_params() */
42+
4243

4344
PG_FUNCTION_INFO_V1(xslt_process);
4445

@@ -129,12 +130,11 @@ xslt_process(PG_FUNCTION_ARGS)
129130
}
130131

131132

132-
void
133+
static void
133134
parse_params(const char **params, text *paramstr)
134135
{
135136
char *pos;
136137
char *pstr;
137-
138138
int i;
139139
char *nvsep = "=";
140140
char *itsep = ",";
@@ -154,11 +154,13 @@ parse_params(const char **params, text *paramstr)
154154
}
155155
else
156156
{
157-
params[i] = NULL;
157+
/* No equal sign, so ignore this "parameter" */
158+
/* We'll reset params[i] to NULL below the loop */
158159
break;
159160
}
160161
/* Value */
161162
i++;
163+
/* since MAXPARAMS is even, we still have i < MAXPARAMS */
162164
params[i] = pos;
163165
pos = strstr(pos, itsep);
164166
if (pos != NULL)
@@ -167,9 +169,11 @@ parse_params(const char **params, text *paramstr)
167169
pos++;
168170
}
169171
else
172+
{
173+
i++;
170174
break;
171-
175+
}
172176
}
173-
if (i < MAXPARAMS)
174-
params[i + 1] = NULL;
177+
178+
params[i] = NULL;
175179
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy