From: Peter Eisentraut Date: Wed, 15 Jul 2026 05:59:42 +0000 (+0200) Subject: Clean up secure_read()/secure_write() return type X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7d45a6dc19743d999f5c83c95ad144a0f2eb6745;p=thirdparty%2Fpostgresql.git Clean up secure_read()/secure_write() return type 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 Discussion: https://www.postgresql.org/message-id/flat/f9aab072-0078-49e4-ab93-3b08086a4406@eisentraut.org --- diff --git a/src/backend/libpq/be-secure-openssl.c b/src/backend/libpq/be-secure-openssl.c index 4ce2a92b964..3674f3cd5de 100644 --- a/src/backend/libpq/be-secure-openssl.c +++ b/src/backend/libpq/be-secure-openssl.c @@ -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) { diff --git a/src/backend/libpq/pqcomm.c b/src/backend/libpq/pqcomm.c index 4a442f22df6..ee9a39107e6 100644 --- a/src/backend/libpq/pqcomm.c +++ b/src/backend/libpq/pqcomm.c @@ -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); diff --git a/src/interfaces/libpq/fe-misc.c b/src/interfaces/libpq/fe-misc.c index f11b58bf9c7..31bc436ac39 100644 --- a/src/interfaces/libpq/fe-misc.c +++ b/src/interfaces/libpq/fe-misc.c @@ -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); diff --git a/src/interfaces/libpq/fe-secure-openssl.c b/src/interfaces/libpq/fe-secure-openssl.c index c7651c98ab5..3e9b87940b2 100644 --- a/src/interfaces/libpq/fe-secure-openssl.c +++ b/src/interfaces/libpq/fe-secure-openssl.c @@ -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) {