Check return of pg_b64_encode() for error
authorPeter Eisentraut <peter@eisentraut.org>
Thu, 16 Jan 2025 07:35:57 +0000 (08:35 +0100)
committerPeter Eisentraut <peter@eisentraut.org>
Thu, 16 Jan 2025 07:35:57 +0000 (08:35 +0100)
Forgotten in commit 761c79508e7.

Author: Ranier Vilela <ranier.vf@gmail.com>
Discussion: https://www.postgresql.org/message-id/flat/CAEudQAq-3yHsSdWoOOaw%2BgAQYgPMpMGuB5pt2yCXgv-YuxG2Hg%40mail.gmail.com

contrib/postgres_fdw/connection.c

index 0274d6c253da2c91ca165a96c8cc7c1b0def7283..8a8d3b4481f3d64c42bbf8a595b94b02e2753424 100644 (file)
@@ -559,23 +559,28 @@ connect_pg_server(ForeignServer *server, UserMapping *user)
        if (MyProcPort->has_scram_keys && UseScramPassthrough(server, user))
        {
            int         len;
+           int         encoded_len;
 
            keywords[n] = "scram_client_key";
            len = pg_b64_enc_len(sizeof(MyProcPort->scram_ClientKey));
            /* don't forget the zero-terminator */
            values[n] = palloc0(len + 1);
-           pg_b64_encode((const char *) MyProcPort->scram_ClientKey,
-                         sizeof(MyProcPort->scram_ClientKey),
-                         (char *) values[n], len);
+           encoded_len = pg_b64_encode((const char *) MyProcPort->scram_ClientKey,
+                                       sizeof(MyProcPort->scram_ClientKey),
+                                       (char *) values[n], len);
+           if (encoded_len < 0)
+               elog(ERROR, "could not encode SCRAM client key");
            n++;
 
            keywords[n] = "scram_server_key";
            len = pg_b64_enc_len(sizeof(MyProcPort->scram_ServerKey));
            /* don't forget the zero-terminator */
            values[n] = palloc0(len + 1);
-           pg_b64_encode((const char *) MyProcPort->scram_ServerKey,
-                         sizeof(MyProcPort->scram_ServerKey),
-                         (char *) values[n], len);
+           encoded_len = pg_b64_encode((const char *) MyProcPort->scram_ServerKey,
+                                       sizeof(MyProcPort->scram_ServerKey),
+                                       (char *) values[n], len);
+           if (encoded_len < 0)
+               elog(ERROR, "could not encode SCRAM server key");
            n++;
        }