Fix health check process issues pointed out by Coverity.
authorTatsuo Ishii <ishii@sraoss.co.jp>
Wed, 2 Feb 2022 01:04:06 +0000 (10:04 +0900)
committerTatsuo Ishii <ishii@sraoss.co.jp>
Wed, 2 Feb 2022 01:06:47 +0000 (10:06 +0900)
Fix possible NULL terminate missing and memory leak when running in test mode.

src/main/health_check.c

index fe0bf9805ca31038db1cd43f54b30a7adbded15e..d0c83788f9c6ac7c1122f52242ac286d269d6805 100644 (file)
@@ -5,7 +5,7 @@
  * pgpool: a language independent connection pool server for PostgreSQL
  * written by Tatsuo Ishii
  *
- * Copyright (c) 2003-2021     PgPool Global Development Group
+ * Copyright (c) 2003-2022     PgPool Global Development Group
  *
  * Permission to use, copy, modify, and distribute this software and
  * its documentation for any purpose and without fee is hereby
@@ -466,7 +466,7 @@ check_backend_down_request(int node, bool done_requests)
                if (fgets(readbuf, MAXLINE - 1, fd) == 0)
                        break;
 
-               strncpy(buf, readbuf, sizeof(buf));
+               strncpy(buf, readbuf, sizeof(buf) - 1);
                if (strlen(readbuf) > 0 && readbuf[strlen(readbuf) - 1] == '\n')
                        buf[strlen(readbuf) - 1] = '\0';
 
@@ -499,6 +499,9 @@ check_backend_down_request(int node, bool done_requests)
 
        fclose(fd);
 
+       if (writebuf)
+               free(writebuf);
+
        if (!found)
                return false;