I propose the attached patch to make pg_upgrade error out on too many
command-line arguments.  This makes it match the behavior of other
PostgreSQL programs.

See [0] for an issue related to the lack of this check:

[0]:
https://www.postgresql.org/message-id/871sdbzizp.fsf%40jsievers.enova.com

-- 
Peter Eisentraut              http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services
From 64bbb562b90bd6272988c608524da2339323f114 Mon Sep 17 00:00:00 2001
From: Peter Eisentraut <pe...@eisentraut.org>
Date: Sun, 25 Aug 2019 10:46:07 +0200
Subject: [PATCH] pg_upgrade: Error out on too many command-line arguments

This makes it match the behavior of other PostgreSQL programs.

pg_upgrade doesn't take any non-option arguments, so these are always
a mistake.
---
 src/bin/pg_upgrade/option.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/src/bin/pg_upgrade/option.c b/src/bin/pg_upgrade/option.c
index e4093ed5af..6afdbeabc8 100644
--- a/src/bin/pg_upgrade/option.c
+++ b/src/bin/pg_upgrade/option.c
@@ -218,6 +218,9 @@ parseCommandLine(int argc, char *argv[])
                }
        }
 
+       if (optind < argc)
+               pg_fatal("too many command-line arguments (first is \"%s\")\n", 
argv[optind]);
+
        if ((log_opts.internal = fopen_priv(INTERNAL_LOG_FILE, "a")) == NULL)
                pg_fatal("could not open log file \"%s\": %m\n", 
INTERNAL_LOG_FILE);
 
-- 
2.22.0

Reply via email to