Skip to content

Commit

Permalink
Make fallback MD5 implementation thread-safe on big-endian systems
Browse files Browse the repository at this point in the history
Replace a static scratch buffer with a local variable, because a
static buffer makes the function not thread-safe. This function is
used in client-code in libpq, so it needs to be thread-safe. It was
until commit b67b57a, which replaced the implementation with the
one from pgcrypto.

Backpatch to v14, where we switched to the new implementation.

Reviewed-by: Robert Haas, Michael Paquier
Discussion: https://www.postgresql.org/message-id/[email protected]
(cherry picked from commit a38f5f880d1e86fedf1616de5391df5f0d5e4239)
  • Loading branch information
hlinnaka authored and shardgupta committed Dec 6, 2024
1 parent 4f2fc27 commit 5d0eadb
Showing 1 changed file with 1 addition and 4 deletions.
5 changes: 1 addition & 4 deletions src/common/md5.c
Original file line number Diff line number Diff line change
Expand Up @@ -150,10 +150,6 @@ static const uint8 md5_paddat[MD5_BUFLEN] = {
0, 0, 0, 0, 0, 0, 0, 0,
};

#ifdef WORDS_BIGENDIAN
static uint32 X[16];
#endif

static void
md5_calc(const uint8 *b64, pg_md5_ctx *ctx)
{
Expand All @@ -167,6 +163,7 @@ md5_calc(const uint8 *b64, pg_md5_ctx *ctx)
#else
/* 4 byte words */
/* what a brute force but fast! */
uint32 X[16];
uint8 *y = (uint8 *) X;

y[0] = b64[3];
Expand Down

0 comments on commit 5d0eadb

Please sign in to comment.