Fix assorted ancient v2 protocol bugs.
authorTatsuo Ishii <ishii@sraoss.co.jp>
Thu, 10 Oct 2019 01:01:08 +0000 (10:01 +0900)
committerTatsuo Ishii <ishii@sraoss.co.jp>
Thu, 10 Oct 2019 01:01:08 +0000 (10:01 +0900)
- In v2 code path, extract_message() pfrees memory which was returned
  from pool_read_string(). This is plain wrong and could cause sefault
  since the memory returned by it is being managed by pool_stream
  modules.

- In v2 code path pool_process_notice_message_from_one_backend() added
  "NOTICE:" to the log message. This is not necessary as the part is
  already included in the message.

- In v2 code path pool_extract_error_message() did not prepare unread
  data correctly. This caused subsequent
  pool_process_notice_message_from_one_backend() produces empty
  message, read_kind_from_backend() failure.

src/protocol/pool_process_query.c

index 52c613a909156c4ce06a790a7666a691a3ee54b9..a4f45833dd3d18a567b33718be793e2d36816432 100644 (file)
@@ -4301,7 +4301,7 @@ extract_message(POOL_CONNECTION * backend, char *error_code, int major, char cla
                pool_unread(backend, &kind, sizeof(kind));
        }
 
-       if (str)
+       if (major == PROTO_MAJOR_V3 && str)
                pfree(str);
 
        return is_error;
@@ -4382,7 +4382,7 @@ pool_process_notice_message_from_one_backend(POOL_CONNECTION * frontend, POOL_CO
 
                /* produce a pgpool log entry */
                ereport(LOG,
-                               (errmsg("backend [%d]: NOTICE: %s", backend_idx, str)));
+                               (errmsg("backend [%d]: %s", backend_idx, str)));
                /* forward it to the frontend */
                pool_write(frontend, &kind, 1);
                pool_write_and_flush(frontend, str, len);
@@ -4482,7 +4482,8 @@ pool_extract_error_message(bool read_kind, POOL_CONNECTION * backend, int major,
                {
                        str = pool_read_string(backend, &len, 0);
                        readlen += len;
-                       appendStringInfoString(str_message_buf, str);
+                       appendBinaryStringInfo(str_message_buf, str, len);
+                       appendBinaryStringInfo(str_buf, str, len);
                }
 
                if (unread)