pgpool2.git / summary / log / commit / refs
commit f5798ff8b85e485d4848fcb480e012b83a1dfba5
Author: Tatsuo Ishii <ishii@sraoss.co.jp>
Date: Mon Jul 17 10:27:43 2023 +0000
Fix crash when v2 protocol is used.
When read_kind_from_backend() accumulates statistics data, it was not
prepared for v2 protocol case.
Bug report and patch from MCanivez.
https://www.pgpool.net/mantisbt/view.php?id=807
Slightly modified by me.
src/protocol/pool_process_query.c | 37 ++++++++++++++++++++++++-------------
1 file changed, 24 insertions(+), 13 deletions(-)
diff --git a/src/protocol/pool_process_query.c b/src/protocol/pool_process_query.c
index 172b764c4..ee2fda8f7 100644
--- a/src/protocol/pool_process_query.c
+++ b/src/protocol/pool_process_query.c
@@ -3521,19 +3521,30 @@ read_kind_from_backend(POOL_CONNECTION * frontend, POOL_CONNECTION_POOL * backen
{
if (kind_list[i] == 'E')
{
- pool_read(CONNECTION(backend, i), &len, sizeof(len));
- unread_len = sizeof(len);
- unread_p = palloc(ntohl(len));
- memcpy(unread_p, &len, sizeof(len));
- len = ntohl(len);
- len -= 4;
- unread_p = repalloc(unread_p, sizeof(len) + len);
- p = pool_read2(CONNECTION(backend, i), len);
- memcpy(unread_p + sizeof(len), p, len);
- unread_len += len;
- error_stat_count_up(i, extract_error_kind(unread_p + sizeof(len), PROTO_MAJOR_V3));
- pool_unread(CONNECTION(backend, i), unread_p, unread_len);
- pfree(unread_p);
+ int major = MAJOR(CONNECTION(backend, i));
+
+ if (major == PROTO_MAJOR_V3)
+ {
+ pool_read(CONNECTION(backend, i), &len, sizeof(len));
+ unread_len = sizeof(len);
+ unread_p = palloc(ntohl(len));
+ memcpy(unread_p, &len, sizeof(len));
+ len = ntohl(len);
+ len -= 4;
+ unread_p = repalloc(unread_p, sizeof(len) + len);
+ p = pool_read2(CONNECTION(backend, i), len);
+ memcpy(unread_p + sizeof(len), p, len);
+ unread_len += len;
+ error_stat_count_up(i, extract_error_kind(unread_p + sizeof(len), PROTO_MAJOR_V3));
+ pool_unread(CONNECTION(backend, i), unread_p, unread_len);
+ pfree(unread_p);
+ }
+ else if (major == PROTO_MAJOR_V2)
+ {
+ unread_p = pool_read_string(CONNECTION(backend, i), &unread_len, 0);
+ error_stat_count_up(i, extract_error_kind(unread_p, PROTO_MAJOR_V2));
+ pool_unread(CONNECTION(backend, i), unread_p, unread_len);
+ }
}
}
}
[parent: 0d54c68d5cfb]