Skip to content

Commit 4944852

Browse files
committed
Add missing return code checks in the uuid-ossp contrib module, per bug #3841.
1 parent 7284dfe commit 4944852

File tree

1 file changed

+53
-13
lines changed

1 file changed

+53
-13
lines changed

contrib/uuid-ossp/uuid-ossp.c

Lines changed: 53 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
*
55
* Copyright (c) 2007 PostgreSQL Global Development Group
66
*
7-
* $PostgreSQL: pgsql/contrib/uuid-ossp/uuid-ossp.c,v 1.5 2007/11/15 22:25:14 momjian Exp $
7+
* $PostgreSQL: pgsql/contrib/uuid-ossp/uuid-ossp.c,v 1.6 2007/12/31 03:55:50 alvherre Exp $
88
*
99
*-------------------------------------------------------------------------
1010
*/
@@ -64,15 +64,32 @@ PG_FUNCTION_INFO_V1(uuid_generate_v3);
6464
PG_FUNCTION_INFO_V1(uuid_generate_v4);
6565
PG_FUNCTION_INFO_V1(uuid_generate_v5);
6666

67+
static void
68+
pguuid_complain(uuid_rc_t rc)
69+
{
70+
char *err = uuid_error(rc);
71+
72+
if (err != NULL)
73+
ereport(ERROR,
74+
(errcode(ERRCODE_EXTERNAL_ROUTINE_EXCEPTION),
75+
errmsg("OSSP uuid library failure: %s", err)));
76+
else
77+
ereport(ERROR,
78+
(errcode(ERRCODE_EXTERNAL_ROUTINE_EXCEPTION),
79+
errmsg("OSSP uuid library failure: error code %d", rc)));
80+
}
6781

6882
static char *
6983
uuid_to_string(const uuid_t * uuid)
7084
{
7185
char *buf = palloc(UUID_LEN_STR + 1);
7286
void *ptr = buf;
7387
size_t len = UUID_LEN_STR + 1;
88+
uuid_rc_t rc;
7489

75-
uuid_export(uuid, UUID_FMT_STR, &ptr, &len);
90+
rc = uuid_export(uuid, UUID_FMT_STR, &ptr, &len);
91+
if (rc != UUID_RC_OK)
92+
pguuid_complain(rc);
7693

7794
return buf;
7895
}
@@ -81,7 +98,11 @@ uuid_to_string(const uuid_t * uuid)
8198
static void
8299
string_to_uuid(const char *str, uuid_t * uuid)
83100
{
84-
uuid_import(uuid, UUID_FMT_STR, str, UUID_LEN_STR + 1);
101+
uuid_rc_t rc;
102+
103+
rc = uuid_import(uuid, UUID_FMT_STR, str, UUID_LEN_STR + 1);
104+
if (rc != UUID_RC_OK)
105+
pguuid_complain(rc);
85106
}
86107

87108

@@ -90,11 +111,18 @@ special_uuid_value(const char *name)
90111
{
91112
uuid_t *uuid;
92113
char *str;
93-
94-
uuid_create(&uuid);
95-
uuid_load(uuid, name);
114+
uuid_rc_t rc;
115+
116+
rc = uuid_create(&uuid);
117+
if (rc != UUID_RC_OK)
118+
pguuid_complain(rc);
119+
rc = uuid_load(uuid, name);
120+
if (rc != UUID_RC_OK)
121+
pguuid_complain(rc);
96122
str = uuid_to_string(uuid);
97-
uuid_destroy(uuid);
123+
rc = uuid_destroy(uuid);
124+
if (rc != UUID_RC_OK)
125+
pguuid_complain(rc);
98126

99127
return DirectFunctionCall1(uuid_in, CStringGetDatum(str));
100128
}
@@ -140,11 +168,18 @@ uuid_generate_internal(int mode, const uuid_t * ns, const char *name)
140168
{
141169
uuid_t *uuid;
142170
char *str;
143-
144-
uuid_create(&uuid);
145-
uuid_make(uuid, mode, ns, name);
171+
uuid_rc_t rc;
172+
173+
rc = uuid_create(&uuid);
174+
if (rc != UUID_RC_OK)
175+
pguuid_complain(rc);
176+
rc = uuid_make(uuid, mode, ns, name);
177+
if (rc != UUID_RC_OK)
178+
pguuid_complain(rc);
146179
str = uuid_to_string(uuid);
147-
uuid_destroy(uuid);
180+
rc = uuid_destroy(uuid);
181+
if (rc != UUID_RC_OK)
182+
pguuid_complain(rc);
148183

149184
return DirectFunctionCall1(uuid_in, CStringGetDatum(str));
150185
}
@@ -169,16 +204,21 @@ uuid_generate_v35_internal(int mode, pg_uuid_t *ns, text *name)
169204
{
170205
uuid_t *ns_uuid;
171206
Datum result;
207+
uuid_rc_t rc;
172208

173-
uuid_create(&ns_uuid);
209+
rc = uuid_create(&ns_uuid);
210+
if (rc != UUID_RC_OK)
211+
pguuid_complain(rc);
174212
string_to_uuid(DatumGetCString(DirectFunctionCall1(uuid_out, UUIDPGetDatum(ns))),
175213
ns_uuid);
176214

177215
result = uuid_generate_internal(mode,
178216
ns_uuid,
179217
DatumGetCString(DirectFunctionCall1(textout, PointerGetDatum(name))));
180218

181-
uuid_destroy(ns_uuid);
219+
rc = uuid_destroy(ns_uuid);
220+
if (rc != UUID_RC_OK)
221+
pguuid_complain(rc);
182222

183223
return result;
184224
}

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