pgpool2.git / summary / log / commit / refs
commit 20c341d91ba9b438102f2cac3678b4ee837afb2f
Author: Bo Peng <pengbo@sraoss.co.jp>
Date: Thu Oct 01 05:22:32 2020 +0000
Add validation for pgpool_node_id file.
src/config/pool_config_variables.c | 25 +++++++++++++++++++++++++
1 file changed, 25 insertions(+)
diff --git a/src/config/pool_config_variables.c b/src/config/pool_config_variables.c
index 2b7757054..443347b07 100644
--- a/src/config/pool_config_variables.c
+++ b/src/config/pool_config_variables.c
@@ -4879,6 +4879,7 @@ SetPgpoolNodeId(int elevel)
char pgpool_node_id_file[POOLMAXPATHLEN + 1];
FILE *fd;
int length;
+ int i;
if (g_pool_config.use_watchdog)
{
@@ -4908,8 +4909,32 @@ SetPgpoolNodeId(int elevel)
length = strlen(readbuf);
if (length > 0 && readbuf[length - 1] == '\n')
+ {
readbuf[length - 1] = '\0';
+ length = strlen(readbuf);
+ if (length <= 0)
+ {
+ ereport(elevel,
+ (errmsg("pgpool_node_id file is empty"),
+ errdetail("If watchdog is enable, we need to specify pgpool node id in %s file", pgpool_node_id_file)));
+ fclose(fd);
+ return false;
+ }
+ }
+
+ for (i = 0; i < length; i++)
+ {
+ if (!isdigit((int) readbuf[i]))
+ {
+ ereport(elevel,
+ (errmsg("pgpool_node_id is not a numeric value"),
+ errdetail("Please specify a numeric value in %s file", pgpool_node_id_file)));
+ fclose(fd);
+ return false;
+ }
+ }
+
g_pool_config.pgpool_node_id = atoi(readbuf);
if (g_pool_config.pgpool_node_id < 0 || g_pool_config.pgpool_node_id > MAX_WATCHDOG_NUM)
[parent: 05a5ab950ad3]