From 0a6c308944301486a9a502c377e49e4db222b207 Mon Sep 17 00:00:00 2001 From: Tatsuo Ishii Date: Sat, 11 Apr 2020 14:34:40 +0900 Subject: [PATCH] Fix pool show command code. Enhance common function send_complete_and_ready() so that it uses local variable in more sane way. Also fix unnecessary limitation of number of rows affected by the command. Patch provided by sherlockcpp and Tatsuo Ishii. --- src/utils/pool_process_reporting.c | 24 ++++++++---------------- 1 file changed, 8 insertions(+), 16 deletions(-) diff --git a/src/utils/pool_process_reporting.c b/src/utils/pool_process_reporting.c index 54eb8b70c..7d5c3d617 100644 --- a/src/utils/pool_process_reporting.c +++ b/src/utils/pool_process_reporting.c @@ -108,39 +108,31 @@ send_row_description(POOL_CONNECTION * frontend, POOL_CONNECTION_POOL * backend, } /* - * send the command complete and ready for query message + * Send the command complete and ready for query message * to frontend. - * if the num_row is passed with a -ve value it is not included - * to the command complete message + * If the num_row is lower than 0, it is not included + * to the command complete message. */ void send_complete_and_ready(POOL_CONNECTION * frontend, POOL_CONNECTION_POOL * backend, const char *message, const int num_rows) { int len; int msg_len; - char msg[16]; + char msg[64]; if (num_rows >= 0) - msg_len = snprintf(msg, 16, "%s %d", message, num_rows); + msg_len = snprintf(msg, sizeof(msg), "%s %d", message, num_rows); else - msg_len = snprintf(msg, 16, "%s", message); - - /* - * if we had more than 16 bytes, including '\0', the string was - * truncatured shouldn't happen though, as it would means more than - * "SELECT 99999999" - */ - if (msg_len > 15) - msg_len = 15; + msg_len = snprintf(msg, sizeof(msg), "%s", message); /* complete command response */ pool_write(frontend, "C", 1); if (MAJOR(backend) == PROTO_MAJOR_V3) { - len = htonl(4 + strlen(msg) + 1); + len = htonl(4 + msg_len + 1); pool_write(frontend, &len, sizeof(len)); } - pool_write(frontend, msg, strlen(msg) + 1); + pool_write(frontend, msg, msg_len + 1); /* ready for query */ pool_write(frontend, "Z", 1); -- 2.39.5