diff options
author | Alvaro Herrera <alvherre@alvh.no-ip.org> | 2020-02-10 12:14:58 -0300 |
---|---|---|
committer | Alvaro Herrera <alvherre@alvh.no-ip.org> | 2020-02-10 12:14:58 -0300 |
commit | 87d014da99bf7613ce76938a9d58e99ef984737a (patch) | |
tree | b082b80e7592fa2d88c344fbf590f0cac83981e9 | |
parent | 2ad125322d5be8b264f2b0945d7dd23ba3ace60e (diff) | |
download | postgresql-87d014da99bf7613ce76938a9d58e99ef984737a.tar.gz postgresql-87d014da99bf7613ce76938a9d58e99ef984737a.zip |
createuser: fix parsing of --connection-limit argument
The original coding failed to quote the argument properly.
Reported-by: Daniel Gustafsson
Discussion: 1B8AE66C-85AB-4728-9BB4-612E8E61C219@yesql.se
-rw-r--r-- | src/bin/scripts/createuser.c | 17 |
1 files changed, 13 insertions, 4 deletions
diff --git a/src/bin/scripts/createuser.c b/src/bin/scripts/createuser.c index 973ba525b25..c65bb2958de 100644 --- a/src/bin/scripts/createuser.c +++ b/src/bin/scripts/createuser.c @@ -63,7 +63,7 @@ main(int argc, char *argv[]) enum trivalue prompt_password = TRI_DEFAULT; bool echo = false; bool interactive = false; - char *conn_limit = NULL; + int conn_limit = -2; /* less than minimum valid value */ bool pwprompt = false; char *newpassword = NULL; char newuser_buf[128]; @@ -91,6 +91,8 @@ main(int argc, char *argv[]) while ((c = getopt_long(argc, argv, "h:p:U:g:wWedDsSaArRiIlLc:PE", long_options, &optindex)) != -1) { + char *endptr; + switch (c) { case 'h': @@ -147,7 +149,14 @@ main(int argc, char *argv[]) login = TRI_NO; break; case 'c': - conn_limit = pg_strdup(optarg); + conn_limit = strtol(optarg, &endptr, 10); + if (*endptr != '\0' || conn_limit < -1) /* minimum valid value */ + { + fprintf(stderr, + _("%s: invalid value for --connection-limit: %s\n"), + progname, optarg); + exit(1); + } break; case 'P': pwprompt = true; @@ -302,8 +311,8 @@ main(int argc, char *argv[]) appendPQExpBufferStr(&sql, " REPLICATION"); if (replication == TRI_NO) appendPQExpBufferStr(&sql, " NOREPLICATION"); - if (conn_limit != NULL) - appendPQExpBuffer(&sql, " CONNECTION LIMIT %s", conn_limit); + if (conn_limit >= -1) + appendPQExpBuffer(&sql, " CONNECTION LIMIT %d", conn_limit); if (roles.head != NULL) { SimpleStringListCell *cell; |