diff options
author | Alvaro Herrera | 2020-02-10 15:14:58 +0000 |
---|---|---|
committer | Alvaro Herrera | 2020-02-10 15:14:58 +0000 |
commit | 6f1e443a65eeee84ec57bd3eb57e54bb5fafbf51 (patch) | |
tree | 4a35372ab6fa212846bedfe0a82fb4ca983b4a4b | |
parent | 3a1acb6b70eb06820c826b0eebb8848be5bc26e8 (diff) |
createuser: fix parsing of --connection-limit argument
The original coding failed to quote the argument properly.
Reported-by: Daniel Gustafsson
Discussion: [email protected]
-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 1b192af678..b9af630388 100644 --- a/src/bin/scripts/createuser.c +++ b/src/bin/scripts/createuser.c @@ -62,7 +62,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; @@ -88,6 +88,8 @@ main(int argc, char *argv[]) while ((c = getopt_long(argc, argv, "h:p:U:g:wWedDsSaArRiIlLc:PEN", long_options, &optindex)) != -1) { + char *endptr; + switch (c) { case 'h': @@ -144,7 +146,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; @@ -305,8 +314,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; |