Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions src/interfaces/libpq/fe-auth-scram.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,13 @@
#include "common/saslprep.h"
#include "common/scram-common.h"
#include "fe-auth.h"
/* Cloudberry */
#include "common/link-canary.h"
#ifndef FRONTEND
#include "utils/palloc.h"
#endif
/* Cloudberry end */

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, but I suggest to remove Cloudberry, Cloudberry end.




/* The exported SCRAM callback mechanism. */
Expand Down Expand Up @@ -147,6 +154,21 @@ scram_init(PGconn *conn,
}
state->password = prep_password;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


/* Cloudberry */
/* After additional linkage frontend code into backend, this function
* may be called on the server side. `pg_saslprep` is compiled for
* backend with palloc memory allocation, but original `scram_free` releases
* the memory with `free` and it leads to abort of running process.
* Reallocation of password right after incorrect allocation seems less
* confusing than usage `free`/`pfree` based on build macro at scram_free
* only for password field.
*/
#ifndef FRONTEND
state->password = strdup(prep_password);
pfree(prep_password);
#endif
Comment on lines +166 to +169

@Vlasdislav Vlasdislav Sep 10, 2026

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
#ifndef FRONTEND
state->password = strdup(prep_password);
pfree(prep_password);
#endif
#ifndef FRONTEND
state->password = strdup(prep_password);
pfree(prep_password);
#else
state->password = prep_password;
#endif

/* Cloudberry end */

return state;
}

Expand Down Expand Up @@ -909,6 +931,14 @@ pg_fe_scram_build_secret(const char *password, int iterations, const char **errs
char saltbuf[SCRAM_DEFAULT_SALT_LEN];
char *result;

/* Cloudberry */
/* Сallers of this function is a frontend applications.
* It's unexpected to call this function at the server code,
* its use will lead to incorrect free of palloc'd memory
*/
Assert(pg_link_canary_is_frontend());
/* Cloudberry end */

/*
* Normalize the password with SASLprep. If that doesn't work, because
* the password isn't valid UTF-8 or contains prohibited characters, just
Expand Down