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

Commit c4b6d21

Browse files
committed
Reject bogus output from uuid_create(3).
When using the BSD UUID functions, contrib/uuid-ossp expects uuid_create() to produce a version-1 UUID. FreeBSD still does so, but in recent NetBSD releases that function produces a version-4 (random) UUID instead. That's not acceptable for our purposes: if the user wanted v4 she would have asked for v4, not v1. Hence, check the version digit and complain if it's not '1'. Also drop the documentation's claim that the NetBSD implementation is usable. It might be, depending on which OS version you're using, but we're not going to get into that kind of detail. (Maybe someday we should ditch all these external libraries and just write our own UUID code, but today is not that day.) Nazir Bilal Yavuz, with cosmetic adjustments and docs by me. Backpatch to all supported versions. Discussion: https://postgr.es/m/3848059.1661038772@sss.pgh.pa.us Discussion: https://postgr.es/m/17358-89806e7420797025@postgresql.org
1 parent 5dcebd1 commit c4b6d21

File tree

3 files changed

+14
-2
lines changed

3 files changed

+14
-2
lines changed

contrib/uuid-ossp/uuid-ossp.c

+12
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,18 @@ uuid_generate_internal(int v, unsigned char *ns, const char *ptr, int len)
284284
{
285285
strlcpy(strbuf, str, 37);
286286

287+
/*
288+
* In recent NetBSD, uuid_create() has started
289+
* producing v4 instead of v1 UUIDs. Check the
290+
* version field and complain if it's not v1.
291+
*/
292+
if (strbuf[14] != '1')
293+
ereport(ERROR,
294+
(errcode(ERRCODE_EXTERNAL_ROUTINE_EXCEPTION),
295+
/* translator: %c will be a hex digit */
296+
errmsg("uuid_create() produced a version %c UUID instead of the expected version 1",
297+
strbuf[14])));
298+
287299
/*
288300
* PTR, if set, replaces the trailing characters of
289301
* the uuid; this is to support v1mc, where a random

doc/src/sgml/installation.sgml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1125,7 +1125,7 @@ build-postgresql:
11251125
<itemizedlist>
11261126
<listitem>
11271127
<para>
1128-
<option>bsd</option> to use the UUID functions found in FreeBSD, NetBSD,
1128+
<option>bsd</option> to use the UUID functions found in FreeBSD
11291129
and some other BSD-derived systems
11301130
</para>
11311131
</listitem>

doc/src/sgml/uuid-ossp.sgml

+1-1
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ SELECT uuid_generate_v3(uuid_ns_url(), 'http://www.postgresql.org');
214214
at <ulink url="http://www.ossp.org/pkg/lib/uuid/"></ulink>, it is not well
215215
maintained, and is becoming increasingly difficult to port to newer
216216
platforms. <filename>uuid-ossp</filename> can now be built without the OSSP
217-
library on some platforms. On FreeBSD, NetBSD, and some other BSD-derived
217+
library on some platforms. On FreeBSD and some other BSD-derived
218218
platforms, suitable UUID creation functions are included in the
219219
core <filename>libc</filename> library. On Linux, macOS, and some other
220220
platforms, suitable functions are provided in the <filename>libuuid</filename>

0 commit comments

Comments
 (0)