From a3996754cc0281293cc5bfb90bf594fef41aff5b Mon Sep 17 00:00:00 2001 From: Bruce Momjian Date: Thu, 6 Oct 2011 19:37:29 -0400 Subject: [PATCH] In pg_upgrade, improve popen() failure detection by checking for fgets() failures. --- contrib/pg_upgrade/check.c | 17 ++++++++--------- contrib/pg_upgrade/controldata.c | 4 ++-- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/contrib/pg_upgrade/check.c b/contrib/pg_upgrade/check.c index ea7464871e..5b9b4cd3d5 100644 --- a/contrib/pg_upgrade/check.c +++ b/contrib/pg_upgrade/check.c @@ -754,11 +754,11 @@ check_for_support_lib(ClusterInfo *cluster) snprintf(cmd, sizeof(cmd), "\"%s/pg_config\" --pkglibdir", cluster->bindir); - if ((output = popen(cmd, "r")) == NULL) - pg_log(PG_FATAL, "Could not get pkglibdir data: %s\n", - getErrorText(errno)); + if ((output = popen(cmd, "r")) == NULL || + fgets(libdir, sizeof(libdir), output) == NULL) + pg_log(PG_FATAL, "Could not get pkglibdir data using %s: %s\n", + cmd, getErrorText(errno)); - fgets(libdir, sizeof(libdir), output); pclose(output); @@ -787,11 +787,10 @@ get_bin_version(ClusterInfo *cluster) snprintf(cmd, sizeof(cmd), "\"%s/pg_ctl\" --version", cluster->bindir); - if ((output = popen(cmd, "r")) == NULL) - pg_log(PG_FATAL, "Could not get pg_ctl version data: %s\n", - getErrorText(errno)); - - fgets(cmd_output, sizeof(cmd_output), output); + if ((output = popen(cmd, "r")) == NULL || + fgets(cmd_output, sizeof(cmd_output), output) == NULL) + pg_log(PG_FATAL, "Could not get pg_ctl version data using %s: %s\n", + cmd, getErrorText(errno)); pclose(output); diff --git a/contrib/pg_upgrade/controldata.c b/contrib/pg_upgrade/controldata.c index 788c690c2a..1120d79783 100644 --- a/contrib/pg_upgrade/controldata.c +++ b/contrib/pg_upgrade/controldata.c @@ -109,8 +109,8 @@ get_control_data(ClusterInfo *cluster, bool live_check) fflush(stderr); if ((output = popen(cmd, "r")) == NULL) - pg_log(PG_FATAL, "Could not get control data: %s\n", - getErrorText(errno)); + pg_log(PG_FATAL, "Could not get control data using %s: %s\n", + cmd, getErrorText(errno)); /* Only pre-8.4 has these so if they are not set below we will check later */ cluster->controldata.lc_collate = NULL; -- 2.40.0