v1-0008-Clean-up-secure_read-secure_write-return-type.patch
text/plain
Filename: v1-0008-Clean-up-secure_read-secure_write-return-type.patch
Type: text/plain
Part: 7
Patch
Format: format-patch
Series: patch v1-0008
Subject: Clean up secure_read()/secure_write() return type
| File | + | − |
|---|---|---|
| src/backend/libpq/be-secure-openssl.c | 2 | 2 |
| src/backend/libpq/pqcomm.c | 3 | 3 |
| src/interfaces/libpq/fe-misc.c | 2 | 2 |
| src/interfaces/libpq/fe-secure-openssl.c | 2 | 2 |
From d6fad81511ebf6343dce9129399ac322dc21f912 Mon Sep 17 00:00:00 2001
From: Peter Eisentraut <peter@eisentraut.org>
Date: Mon, 29 Jun 2026 13:37:54 +0200
Subject: [PATCH v1 08/15] 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.
---
src/backend/libpq/be-secure-openssl.c | 4 ++--
src/backend/libpq/pqcomm.c | 6 +++---
src/interfaces/libpq/fe-misc.c | 4 ++--
src/interfaces/libpq/fe-secure-openssl.c | 4 ++--
4 files changed, 9 insertions(+), 9 deletions(-)
diff --git a/src/backend/libpq/be-secure-openssl.c b/src/backend/libpq/be-secure-openssl.c
index 7890e6c2de2..8a7d335f3fa 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 905344d5c38..b96da766bf4 100644
--- a/src/interfaces/libpq/fe-misc.c
+++ b/src/interfaces/libpq/fe-misc.c
@@ -606,7 +606,7 @@ int
pqReadData(PGconn *conn)
{
int someread = 0;
- int nread;
+ ssize_t nread;
if (conn->sock == PGINVALID_SOCKET)
{
@@ -864,7 +864,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 6b44eeb68eb..bcb134eba32 100644
--- a/src/interfaces/libpq/fe-secure-openssl.c
+++ b/src/interfaces/libpq/fe-secure-openssl.c
@@ -1741,7 +1741,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)
@@ -1775,7 +1775,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)
{
--
2.54.0