Skip to content

Commit 87d014d

Browse files
committed
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
1 parent 2ad1253 commit 87d014d

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

src/bin/scripts/createuser.c

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ main(int argc, char *argv[])
6363
enum trivalue prompt_password = TRI_DEFAULT;
6464
bool echo = false;
6565
bool interactive = false;
66-
char *conn_limit = NULL;
66+
int conn_limit = -2; /* less than minimum valid value */
6767
bool pwprompt = false;
6868
char *newpassword = NULL;
6969
char newuser_buf[128];
@@ -91,6 +91,8 @@ main(int argc, char *argv[])
9191
while ((c = getopt_long(argc, argv, "h:p:U:g:wWedDsSaArRiIlLc:PE",
9292
long_options, &optindex)) != -1)
9393
{
94+
char *endptr;
95+
9496
switch (c)
9597
{
9698
case 'h':
@@ -147,7 +149,14 @@ main(int argc, char *argv[])
147149
login = TRI_NO;
148150
break;
149151
case 'c':
150-
conn_limit = pg_strdup(optarg);
152+
conn_limit = strtol(optarg, &endptr, 10);
153+
if (*endptr != '\0' || conn_limit < -1) /* minimum valid value */
154+
{
155+
fprintf(stderr,
156+
_("%s: invalid value for --connection-limit: %s\n"),
157+
progname, optarg);
158+
exit(1);
159+
}
151160
break;
152161
case 'P':
153162
pwprompt = true;
@@ -302,8 +311,8 @@ main(int argc, char *argv[])
302311
appendPQExpBufferStr(&sql, " REPLICATION");
303312
if (replication == TRI_NO)
304313
appendPQExpBufferStr(&sql, " NOREPLICATION");
305-
if (conn_limit != NULL)
306-
appendPQExpBuffer(&sql, " CONNECTION LIMIT %s", conn_limit);
314+
if (conn_limit >= -1)
315+
appendPQExpBuffer(&sql, " CONNECTION LIMIT %d", conn_limit);
307316
if (roles.head != NULL)
308317
{
309318
SimpleStringListCell *cell;

0 commit comments

Comments
 (0)