Skip to content

Commit ff030eb

Browse files
committed
Check return of pg_b64_encode() for error
Forgotten in commit 761c795. Author: Ranier Vilela <ranier.vf@gmail.com> Discussion: https://www.postgresql.org/message-id/flat/CAEudQAq-3yHsSdWoOOaw%2BgAQYgPMpMGuB5pt2yCXgv-YuxG2Hg%40mail.gmail.com
1 parent 965b2cc commit ff030eb

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

contrib/postgres_fdw/connection.c

+11-6
Original file line numberDiff line numberDiff line change
@@ -559,23 +559,28 @@ connect_pg_server(ForeignServer *server, UserMapping *user)
559559
if (MyProcPort->has_scram_keys && UseScramPassthrough(server, user))
560560
{
561561
int len;
562+
int encoded_len;
562563

563564
keywords[n] = "scram_client_key";
564565
len = pg_b64_enc_len(sizeof(MyProcPort->scram_ClientKey));
565566
/* don't forget the zero-terminator */
566567
values[n] = palloc0(len + 1);
567-
pg_b64_encode((const char *) MyProcPort->scram_ClientKey,
568-
sizeof(MyProcPort->scram_ClientKey),
569-
(char *) values[n], len);
568+
encoded_len = pg_b64_encode((const char *) MyProcPort->scram_ClientKey,
569+
sizeof(MyProcPort->scram_ClientKey),
570+
(char *) values[n], len);
571+
if (encoded_len < 0)
572+
elog(ERROR, "could not encode SCRAM client key");
570573
n++;
571574

572575
keywords[n] = "scram_server_key";
573576
len = pg_b64_enc_len(sizeof(MyProcPort->scram_ServerKey));
574577
/* don't forget the zero-terminator */
575578
values[n] = palloc0(len + 1);
576-
pg_b64_encode((const char *) MyProcPort->scram_ServerKey,
577-
sizeof(MyProcPort->scram_ServerKey),
578-
(char *) values[n], len);
579+
encoded_len = pg_b64_encode((const char *) MyProcPort->scram_ServerKey,
580+
sizeof(MyProcPort->scram_ServerKey),
581+
(char *) values[n], len);
582+
if (encoded_len < 0)
583+
elog(ERROR, "could not encode SCRAM server key");
579584
n++;
580585
}
581586

0 commit comments

Comments
 (0)