Movatterモバイル変換


[0]ホーム

URL:


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

Sign up
Appearance settings

Commit38698dd

Browse files
committed
Unwind #if spaghetti in hmac_openssl.c a bit.
Make this code a little less confusing by defining a separate macrothat controls whether we'll use ResourceOwner facilities to trackthe existence of a pg_hmac_ctx context.The proximate reason to touch this is that sinceb8bff07, we got"unused function" warnings if building with older OpenSSL, becausethe #if guards around the ResourceOwner wrapper function definitionswere different from those around the calls of those functions.Pulling the ResourceOwner machinations outside of the #ifdef HAVE_xxxguards fixes that and makes the code clearer too.Discussion:https://postgr.es/m/1394271.1712016101@sss.pgh.pa.us
1 parentcafe105 commit38698dd

File tree

1 file changed

+18
-14
lines changed

1 file changed

+18
-14
lines changed

‎src/common/hmac_openssl.c

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
*/
4242
#ifndefFRONTEND
4343
#ifdefHAVE_HMAC_CTX_NEW
44+
#defineUSE_RESOWNER_FOR_HMAC
4445
#defineALLOC(size) MemoryContextAlloc(TopMemoryContext, size)
4546
#else
4647
#defineALLOC(size) palloc(size)
@@ -67,13 +68,13 @@ struct pg_hmac_ctx
6768
pg_hmac_errnoerror;
6869
constchar*errreason;
6970

70-
#ifndefFRONTEND
71+
#ifdefUSE_RESOWNER_FOR_HMAC
7172
ResourceOwnerresowner;
7273
#endif
7374
};
7475

7576
/* ResourceOwner callbacks to hold HMAC contexts */
76-
#ifndefFRONTEND
77+
#ifdefUSE_RESOWNER_FOR_HMAC
7778
staticvoidResOwnerReleaseHMAC(Datumres);
7879

7980
staticconstResourceOwnerDeschmac_resowner_desc=
@@ -138,10 +139,12 @@ pg_hmac_create(pg_cryptohash_type type)
138139
* previous runs.
139140
*/
140141
ERR_clear_error();
141-
#ifdefHAVE_HMAC_CTX_NEW
142-
#ifndefFRONTEND
142+
143+
#ifdefUSE_RESOWNER_FOR_HMAC
143144
ResourceOwnerEnlarge(CurrentResourceOwner);
144145
#endif
146+
147+
#ifdefHAVE_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
returnNULL;
160163
}
161164

162-
#ifdefHAVE_HMAC_CTX_NEW
163-
#ifndefFRONTEND
165+
#ifndefHAVE_HMAC_CTX_NEW
166+
memset(ctx->hmacctx,0,sizeof(HMAC_CTX));
167+
#endif
168+
169+
#ifdefUSE_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
returnctx;
172175
}
@@ -327,15 +330,16 @@ pg_hmac_free(pg_hmac_ctx *ctx)
327330

328331
#ifdefHAVE_HMAC_CTX_FREE
329332
HMAC_CTX_free(ctx->hmacctx);
330-
#ifndefFRONTEND
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+
#ifdefUSE_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-
#ifndefFRONTEND
382+
#ifdefUSE_RESOWNER_FOR_HMAC
379383
staticvoid
380384
ResOwnerReleaseHMAC(Datumres)
381385
{

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp