Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 95028d9

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/[email protected] Discussion: https://postgr.es/m/[email protected]
1 parent 174c929 commit 95028d9

File tree

3 files changed

+14
-2
lines changed

3 files changed

+14
-2
lines changed

contrib/uuid-ossp/uuid-ossp.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,18 @@ uuid_generate_internal(int v, unsigned char *ns, char *ptr, int len)
295295
{
296296
strlcpy(strbuf, str, 37);
297297

298+
/*
299+
* In recent NetBSD, uuid_create() has started
300+
* producing v4 instead of v1 UUIDs. Check the
301+
* version field and complain if it's not v1.
302+
*/
303+
if (strbuf[14] != '1')
304+
ereport(ERROR,
305+
(errcode(ERRCODE_EXTERNAL_ROUTINE_EXCEPTION),
306+
/* translator: %c will be a hex digit */
307+
errmsg("uuid_create() produced a version %c UUID instead of the expected version 1",
308+
strbuf[14])));
309+
298310
/*
299311
* PTR, if set, replaces the trailing characters of
300312
* the uuid; this is to support v1mc, where a random

doc/src/sgml/installation.sgml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -920,7 +920,7 @@ su - postgres
920920
<itemizedlist>
921921
<listitem>
922922
<para>
923-
<option>bsd</> to use the UUID functions found in FreeBSD, NetBSD,
923+
<option>bsd</> to use the UUID functions found in FreeBSD
924924
and some other BSD-derived systems
925925
</para>
926926
</listitem>

doc/src/sgml/uuid-ossp.sgml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ SELECT uuid_generate_v3(uuid_ns_url(), 'http://www.postgresql.org');
167167
at <ulink url="http://www.ossp.org/pkg/lib/uuid/"></ulink>, it is not well
168168
maintained, and is becoming increasingly difficult to port to newer
169169
platforms. <filename>uuid-ossp</> can now be built without the OSSP
170-
library on some platforms. On FreeBSD, NetBSD, and some other BSD-derived
170+
library on some platforms. On FreeBSD and some other BSD-derived
171171
platforms, suitable UUID creation functions are included in the
172172
core <filename>libc</> library. On Linux, macOS, and some other
173173
platforms, suitable functions are provided in the <filename>libuuid</>

0 commit comments

Comments
 (0)