Skip to content

Commit d4ab396

Browse files
committed
Make contrib/unaccent's unaccent() function work when not in search path.
Since the fixes for CVE-2018-1058, we've advised people to schema-qualify function references in order to fix failures in code that executes under a minimal search_path setting. However, that's insufficient to make the single-argument form of unaccent() work, because it looks up the "unaccent" text search dictionary using the search path. The most expedient answer seems to be to remove the search_path dependency by making it look in the same schema that the unaccent() function itself is declared in. This will definitely work for the normal usage of this function with the unaccent dictionary provided by the extension. It's barely possible that there are people who were relying on the search-path-dependent behavior to select other dictionaries with the same name; but if there are any such people at all, they can still get that behavior by writing unaccent('unaccent', ...), or possibly unaccent('unaccent'::text::regdictionary, ...) if the lookup has to be postponed to runtime. Per complaint from Gunnlaugur Thor Briem. Back-patch to all supported branches. Discussion: https://postgr.es/m/CAPs+M8LCex6d=DeneofdsoJVijaG59m9V0ggbb3pOH7hZO4+cQ@mail.gmail.com
1 parent 20ce873 commit d4ab396

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-2
lines changed

contrib/unaccent/unaccent.c

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
#include "tsearch/ts_locale.h"
2121
#include "tsearch/ts_public.h"
2222
#include "utils/builtins.h"
23+
#include "utils/lsyscache.h"
24+
#include "utils/syscache.h"
2325

2426
PG_MODULE_MAGIC;
2527

@@ -325,7 +327,21 @@ unaccent_dict(PG_FUNCTION_ARGS)
325327

326328
if (PG_NARGS() == 1)
327329
{
328-
dictOid = get_ts_dict_oid(stringToQualifiedNameList("unaccent"), false);
330+
/*
331+
* Use the "unaccent" dictionary that is in the same schema that this
332+
* function is in.
333+
*/
334+
Oid procnspid = get_func_namespace(fcinfo->flinfo->fn_oid);
335+
const char *dictname = "unaccent";
336+
337+
dictOid = GetSysCacheOid2(TSDICTNAMENSP,
338+
PointerGetDatum(dictname),
339+
ObjectIdGetDatum(procnspid));
340+
if (!OidIsValid(dictOid))
341+
ereport(ERROR,
342+
(errcode(ERRCODE_UNDEFINED_OBJECT),
343+
errmsg("text search dictionary \"%s.%s\" does not exist",
344+
get_namespace_name(procnspid), dictname)));
329345
strArg = 0;
330346
}
331347
else

doc/src/sgml/unaccent.sgml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,9 +142,16 @@ mydb=# select ts_headline('fr','Hôtel de la Mer',to_tsquery('fr','Hotels')
142142
</indexterm>
143143

144144
<synopsis>
145-
unaccent(<optional><replaceable class="PARAMETER">dictionary</replaceable>, </optional> <replaceable class="PARAMETER">string</replaceable>) returns <type>text</type>
145+
unaccent(<optional><replaceable class="parameter">dictionary</replaceable> <type>regdictionary</type>, </optional> <replaceable class="parameter">string</replaceable> <type>text</type>) returns <type>text</type>
146146
</synopsis>
147147

148+
<para>
149+
If the <replaceable class="parameter">dictionary</replaceable> argument is
150+
omitted, the text search dictionary named <literal>unaccent</literal> and
151+
appearing in the same schema as the <function>unaccent()</function>
152+
function itself is used.
153+
</para>
154+
148155
<para>
149156
For example:
150157
<programlisting>

0 commit comments

Comments
 (0)