Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit a5322ca

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 842cb9f commit a5322ca

File tree

2 files changed

+21
-3
lines changed

2 files changed

+21
-3
lines changed

contrib/unaccent/unaccent.c

+17-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@
2020
#include "tsearch/ts_locale.h"
2121
#include "tsearch/ts_public.h"
2222
#include "utils/builtins.h"
23+
#include "utils/lsyscache.h"
2324
#include "utils/regproc.h"
25+
#include "utils/syscache.h"
2426

2527
PG_MODULE_MAGIC;
2628

@@ -376,7 +378,21 @@ unaccent_dict(PG_FUNCTION_ARGS)
376378

377379
if (PG_NARGS() == 1)
378380
{
379-
dictOid = get_ts_dict_oid(stringToQualifiedNameList("unaccent"), false);
381+
/*
382+
* Use the "unaccent" dictionary that is in the same schema that this
383+
* function is in.
384+
*/
385+
Oid procnspid = get_func_namespace(fcinfo->flinfo->fn_oid);
386+
const char *dictname = "unaccent";
387+
388+
dictOid = GetSysCacheOid2(TSDICTNAMENSP,
389+
PointerGetDatum(dictname),
390+
ObjectIdGetDatum(procnspid));
391+
if (!OidIsValid(dictOid))
392+
ereport(ERROR,
393+
(errcode(ERRCODE_UNDEFINED_OBJECT),
394+
errmsg("text search dictionary \"%s.%s\" does not exist",
395+
get_namespace_name(procnspid), dictname)));
380396
strArg = 0;
381397
}
382398
else

doc/src/sgml/unaccent.sgml

+4-2
Original file line numberDiff line numberDiff line change
@@ -174,12 +174,14 @@ mydb=# select ts_headline('fr','Hôtel de la Mer',to_tsquery('fr','Hotels')
174174
</indexterm>
175175

176176
<synopsis>
177-
unaccent(<optional><replaceable class="parameter">dictionary</replaceable>, </optional> <replaceable class="parameter">string</replaceable>) returns <type>text</type>
177+
unaccent(<optional><replaceable class="parameter">dictionary</replaceable> <type>regdictionary</type>, </optional> <replaceable class="parameter">string</replaceable> <type>text</type>) returns <type>text</type>
178178
</synopsis>
179179

180180
<para>
181181
If the <replaceable class="parameter">dictionary</replaceable> argument is
182-
omitted, <literal>unaccent</literal> is assumed.
182+
omitted, the text search dictionary named <literal>unaccent</literal> and
183+
appearing in the same schema as the <function>unaccent()</function>
184+
function itself is used.
183185
</para>
184186

185187
<para>

0 commit comments

Comments
 (0)