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:24:54 +0000 (10:24 +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 1e8525c023bafa70afb8052cc856429121e3af0e..92f20f073deab1a5128b9ffc9fd6e8f3c3541bcd 100644 (file)
@@ -4238,7 +4238,7 @@ static int detect_error(POOL_CONNECTION *backend, char *error_code, int major, c
                pool_unread(backend, &kind, sizeof(kind));
        }
 
-       if (str)
+       if (major == PROTO_MAJOR_V3 && str)
                pfree(str);
 
        return is_error;
@@ -4329,7 +4329,7 @@ static bool pool_process_notice_message_from_one_backend(POOL_CONNECTION *fronte
 
                /* 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);
@@ -4427,7 +4427,8 @@ int pool_extract_error_message(bool read_kind, POOL_CONNECTION *backend, int maj
         {
             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)