Commit 8fa8e011 authored by Alvaro Herrera's avatar Alvaro Herrera

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
parent b048f558
...@@ -60,7 +60,7 @@ main(int argc, char *argv[]) ...@@ -60,7 +60,7 @@ main(int argc, char *argv[])
enum trivalue prompt_password = TRI_DEFAULT; enum trivalue prompt_password = TRI_DEFAULT;
bool echo = false; bool echo = false;
bool interactive = false; bool interactive = false;
char *conn_limit = NULL; int conn_limit = -2; /* less than minimum valid value */
bool pwprompt = false; bool pwprompt = false;
char *newpassword = NULL; char *newpassword = NULL;
char newuser_buf[128]; char newuser_buf[128];
...@@ -88,6 +88,8 @@ main(int argc, char *argv[]) ...@@ -88,6 +88,8 @@ main(int argc, char *argv[])
while ((c = getopt_long(argc, argv, "h:p:U:g:wWedDsSrRiIlLc:PE", while ((c = getopt_long(argc, argv, "h:p:U:g:wWedDsSrRiIlLc:PE",
long_options, &optindex)) != -1) long_options, &optindex)) != -1)
{ {
char *endptr;
switch (c) switch (c)
{ {
case 'h': case 'h':
...@@ -142,7 +144,14 @@ main(int argc, char *argv[]) ...@@ -142,7 +144,14 @@ main(int argc, char *argv[])
login = TRI_NO; login = TRI_NO;
break; break;
case 'c': 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; break;
case 'P': case 'P':
pwprompt = true; pwprompt = true;
...@@ -297,8 +306,8 @@ main(int argc, char *argv[]) ...@@ -297,8 +306,8 @@ main(int argc, char *argv[])
appendPQExpBufferStr(&sql, " REPLICATION"); appendPQExpBufferStr(&sql, " REPLICATION");
if (replication == TRI_NO) if (replication == TRI_NO)
appendPQExpBufferStr(&sql, " NOREPLICATION"); appendPQExpBufferStr(&sql, " NOREPLICATION");
if (conn_limit != NULL) if (conn_limit >= -1)
appendPQExpBuffer(&sql, " CONNECTION LIMIT %s", conn_limit); appendPQExpBuffer(&sql, " CONNECTION LIMIT %d", conn_limit);
if (roles.head != NULL) if (roles.head != NULL)
{ {
SimpleStringListCell *cell; SimpleStringListCell *cell;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment