Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 38698dd

Browse filesBrowse files
committed
Unwind #if spaghetti in hmac_openssl.c a bit.
Make this code a little less confusing by defining a separate macro that controls whether we'll use ResourceOwner facilities to track the existence of a pg_hmac_ctx context. The proximate reason to touch this is that since b8bff07, we got "unused function" warnings if building with older OpenSSL, because the #if guards around the ResourceOwner wrapper function definitions were different from those around the calls of those functions. Pulling the ResourceOwner machinations outside of the #ifdef HAVE_xxx guards fixes that and makes the code clearer too. Discussion: https://postgr.es/m/1394271.1712016101@sss.pgh.pa.us
1 parent cafe105 commit 38698dd
Copy full SHA for 38698dd

File tree

Expand file treeCollapse file tree

1 file changed

+18
-14
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+18
-14
lines changed

‎src/common/hmac_openssl.c

Copy file name to clipboardExpand all lines: src/common/hmac_openssl.c
+18-14Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
*/
4242
#ifndef FRONTEND
4343
#ifdef HAVE_HMAC_CTX_NEW
44+
#define USE_RESOWNER_FOR_HMAC
4445
#define ALLOC(size) MemoryContextAlloc(TopMemoryContext, size)
4546
#else
4647
#define ALLOC(size) palloc(size)
@@ -67,13 +68,13 @@ struct pg_hmac_ctx
6768
pg_hmac_errno error;
6869
const char *errreason;
6970

70-
#ifndef FRONTEND
71+
#ifdef USE_RESOWNER_FOR_HMAC
7172
ResourceOwner resowner;
7273
#endif
7374
};
7475

7576
/* ResourceOwner callbacks to hold HMAC contexts */
76-
#ifndef FRONTEND
77+
#ifdef USE_RESOWNER_FOR_HMAC
7778
static void ResOwnerReleaseHMAC(Datum res);
7879

7980
static const ResourceOwnerDesc hmac_resowner_desc =
@@ -138,10 +139,12 @@ pg_hmac_create(pg_cryptohash_type type)
138139
* previous runs.
139140
*/
140141
ERR_clear_error();
141-
#ifdef HAVE_HMAC_CTX_NEW
142-
#ifndef FRONTEND
142+
143+
#ifdef USE_RESOWNER_FOR_HMAC
143144
ResourceOwnerEnlarge(CurrentResourceOwner);
144145
#endif
146+
147+
#ifdef HAVE_HMAC_CTX_NEW
145148
ctx->hmacctx = HMAC_CTX_new();
146149
#else
147150
ctx->hmacctx = ALLOC(sizeof(HMAC_CTX));
@@ -159,14 +162,14 @@ pg_hmac_create(pg_cryptohash_type type)
159162
return NULL;
160163
}
161164

162-
#ifdef HAVE_HMAC_CTX_NEW
163-
#ifndef FRONTEND
165+
#ifndef HAVE_HMAC_CTX_NEW
166+
memset(ctx->hmacctx, 0, sizeof(HMAC_CTX));
167+
#endif
168+
169+
#ifdef USE_RESOWNER_FOR_HMAC
164170
ctx->resowner = CurrentResourceOwner;
165171
ResourceOwnerRememberHMAC(CurrentResourceOwner, ctx);
166172
#endif
167-
#else
168-
memset(ctx->hmacctx, 0, sizeof(HMAC_CTX));
169-
#endif /* HAVE_HMAC_CTX_NEW */
170173

171174
return ctx;
172175
}
@@ -327,15 +330,16 @@ pg_hmac_free(pg_hmac_ctx *ctx)
327330

328331
#ifdef HAVE_HMAC_CTX_FREE
329332
HMAC_CTX_free(ctx->hmacctx);
330-
#ifndef FRONTEND
331-
if (ctx->resowner)
332-
ResourceOwnerForgetHMAC(ctx->resowner, ctx);
333-
#endif
334333
#else
335334
explicit_bzero(ctx->hmacctx, sizeof(HMAC_CTX));
336335
FREE(ctx->hmacctx);
337336
#endif
338337

338+
#ifdef USE_RESOWNER_FOR_HMAC
339+
if (ctx->resowner)
340+
ResourceOwnerForgetHMAC(ctx->resowner, ctx);
341+
#endif
342+
339343
explicit_bzero(ctx, sizeof(pg_hmac_ctx));
340344
FREE(ctx);
341345
}
@@ -375,7 +379,7 @@ pg_hmac_error(pg_hmac_ctx *ctx)
375379

376380
/* ResourceOwner callbacks */
377381

378-
#ifndef FRONTEND
382+
#ifdef USE_RESOWNER_FOR_HMAC
379383
static void
380384
ResOwnerReleaseHMAC(Datum res)
381385
{

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.