]> git.ipfire.org Git - thirdparty/postgresql.git/commitdiff
Clean up secure_read()/secure_write() return type
authorPeter Eisentraut <peter@eisentraut.org>
Wed, 15 Jul 2026 05:59:42 +0000 (07:59 +0200)
committerPeter Eisentraut <peter@eisentraut.org>
Wed, 15 Jul 2026 05:59:42 +0000 (07:59 +0200)
The return type is ssize_t, not int, but some callers didn't handle
this properly.

The BIO callbacks are constrained by the OpenSSL API, so they take int
for the length and return int.  This is safe, since the return value
can't be greater than the input length.  To make it more clear that
this is intentional, cast the result of the
secure_read()/secure_write() call to int explicitly.

Reviewed-by: Heikki Linnakangas <hlinnaka@iki.fi>
Discussion: https://www.postgresql.org/message-id/flat/f9aab072-0078-49e4-ab93-3b08086a4406@eisentraut.org

src/backend/libpq/be-secure-openssl.c
src/backend/libpq/pqcomm.c
src/interfaces/libpq/fe-misc.c
src/interfaces/libpq/fe-secure-openssl.c

index 4ce2a92b9649be6c6cc4780cdb367d77bafca4b4..3674f3cd5de5bdd6d32ddc05ffc30d3efe70db0c 100644 (file)
@@ -1347,7 +1347,7 @@ port_bio_read(BIO *h, char *buf, int size)
 
        if (buf != NULL)
        {
-               res = secure_raw_read(port, buf, size);
+               res = (int) secure_raw_read(port, buf, size);
                BIO_clear_retry_flags(h);
                port->last_read_was_eof = res == 0;
                if (res <= 0)
@@ -1368,7 +1368,7 @@ port_bio_write(BIO *h, const char *buf, int size)
 {
        int                     res = 0;
 
-       res = secure_raw_write(((Port *) BIO_get_data(h)), buf, size);
+       res = (int) secure_raw_write(((Port *) BIO_get_data(h)), buf, size);
        BIO_clear_retry_flags(h);
        if (res <= 0)
        {
index 4a442f22df60b6c31b8a41623e1ab2af51945267..ee9a39107e6f57fa31e14c76602b177d6f5663f9 100644 (file)
@@ -917,7 +917,7 @@ pq_recvbuf(void)
        /* Can fill buffer from PqRecvLength and upwards */
        for (;;)
        {
-               int                     r;
+               ssize_t         r;
 
                errno = 0;
 
@@ -1003,7 +1003,7 @@ pq_peekbyte(void)
 int
 pq_getbyte_if_available(unsigned char *c)
 {
-       int                     r;
+       ssize_t         r;
 
        Assert(PqCommReadingMsg);
 
@@ -1369,7 +1369,7 @@ internal_flush_buffer(const char *buf, size_t *start, size_t *end)
 
        while (bufptr < bufend)
        {
-               int                     r;
+               ssize_t         r;
 
                r = secure_write(MyProcPort, bufptr, bufend - bufptr);
 
index f11b58bf9c7ca960d19230583b097c569739793c..31bc436ac392139af61bba7b7a9474ac4fd2dddd 100644 (file)
@@ -654,7 +654,7 @@ static int
 pqReadData_internal(PGconn *conn)
 {
        int                     someread = 0;
-       int                     nread;
+       ssize_t         nread;
 
        /* Left-justify any data in the buffer to make room */
        if (conn->inStart < conn->inEnd)
@@ -1010,7 +1010,7 @@ pqSendSome(PGconn *conn, int len)
        /* while there's still data to send */
        while (len > 0)
        {
-               int                     sent;
+               ssize_t         sent;
 
 #ifndef WIN32
                sent = pqsecure_write(conn, ptr, len);
index c7651c98ab52486758e2831d6d725df470a58ee5..3e9b87940b218522dc72d21998f101b753da3a27 100644 (file)
@@ -1772,7 +1772,7 @@ pgconn_bio_read(BIO *h, char *buf, int size)
        PGconn     *conn = (PGconn *) BIO_get_data(h);
        int                     res;
 
-       res = pqsecure_raw_read(conn, buf, size);
+       res = (int) pqsecure_raw_read(conn, buf, size);
        BIO_clear_retry_flags(h);
        conn->last_read_was_eof = res == 0;
        if (res < 0)
@@ -1806,7 +1806,7 @@ pgconn_bio_write(BIO *h, const char *buf, int size)
 {
        int                     res;
 
-       res = pqsecure_raw_write((PGconn *) BIO_get_data(h), buf, size);
+       res = (int) pqsecure_raw_write((PGconn *) BIO_get_data(h), buf, size);
        BIO_clear_retry_flags(h);
        if (res < 0)
        {