diff options
author | Daniel Gustafsson <dgustafsson@postgresql.org> | 2024-02-09 15:03:16 +0100 |
---|---|---|
committer | Daniel Gustafsson <dgustafsson@postgresql.org> | 2024-02-09 15:03:16 +0100 |
commit | 5c7038d70bb9c4d28a80b0a2051f73fafab5af3f (patch) | |
tree | 3cee0d6028b7c26d34246413b14ada54ca65b050 /src/bin/pg_upgrade/exec.c | |
parent | c01f6ef46c8f0ab3faa54e8f040da6e9ddc7fe5b (diff) |
Refactor pipe_read_line to return the full line
Commit 5b2f4afffe6 refactored find_other_exec() and in the process
created pipe_read_line() into a static routine for reading a single
line of output, aimed at reading version numbers. Commit a7e8ece41
later exposed it externally in order to read a postgresql.conf GUC
using "postgres -C ..". Further, f06b1c598 also made use of it for
reading a version string much like find_other_exec(). The internal
variable remained "pgver", even when used for other purposes.
Since the function requires passing a buffer and its size, and at
most size - 1 bytes will be read via fgets(), there is a truncation
risk when using this for reading GUCs (like how pg_rewind does,
though the risk in this case is marginal).
To keep this as generic functionality for reading a line from a pipe,
this refactors pipe_read_line() into returning an allocated buffer
containing all of the line to remove the risk of silent truncation.
Reviewed-by: Heikki Linnakangas <hlinnaka@iki.fi>
Reviewed-by: Álvaro Herrera <alvherre@alvh.no-ip.org>
Reviewed-by: John Naylor <johncnaylorls@gmail.com>
Discussion: https://postgr.es/m/DEDF73CE-D528-49A3-9089-B3592FD671A9@yesql.se
Diffstat (limited to 'src/bin/pg_upgrade/exec.c')
-rw-r--r-- | src/bin/pg_upgrade/exec.c | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/src/bin/pg_upgrade/exec.c b/src/bin/pg_upgrade/exec.c index fec8dc4c2f7..3552cf00afb 100644 --- a/src/bin/pg_upgrade/exec.c +++ b/src/bin/pg_upgrade/exec.c @@ -431,7 +431,7 @@ static void check_exec(const char *dir, const char *program, bool check_version) { char path[MAXPGPATH]; - char line[MAXPGPATH]; + char *line; char cmd[MAXPGPATH]; char versionstr[128]; @@ -442,7 +442,7 @@ check_exec(const char *dir, const char *program, bool check_version) snprintf(cmd, sizeof(cmd), "\"%s\" -V", path); - if (!pipe_read_line(cmd, line, sizeof(line))) + if ((line = pipe_read_line(cmd)) == NULL) pg_fatal("check for \"%s\" failed: cannot execute", path); @@ -456,4 +456,6 @@ check_exec(const char *dir, const char *program, bool check_version) pg_fatal("check for \"%s\" failed: incorrect version: found \"%s\", expected \"%s\"", path, line, versionstr); } + + pg_free(line); } |