Skip to content

Commit 6f1e443

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 3a1acb6 commit 6f1e443

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

src/bin/scripts/createuser.c

+13-4
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ main(int argc, char *argv[])
6262
enum trivalue prompt_password = TRI_DEFAULT;
6363
bool echo = false;
6464
bool interactive = false;
65-
char *conn_limit = NULL;
65+
int conn_limit = -2; /* less than minimum valid value */
6666
bool pwprompt = false;
6767
char *newpassword = NULL;
6868

@@ -88,6 +88,8 @@ main(int argc, char *argv[])
8888
while ((c = getopt_long(argc, argv, "h:p:U:g:wWedDsSaArRiIlLc:PEN",
8989
long_options, &optindex)) != -1)
9090
{
91+
char *endptr;
92+
9193
switch (c)
9294
{
9395
case 'h':
@@ -144,7 +146,14 @@ main(int argc, char *argv[])
144146
login = TRI_NO;
145147
break;
146148
case 'c':
147-
conn_limit = pg_strdup(optarg);
149+
conn_limit = strtol(optarg, &endptr, 10);
150+
if (*endptr != '\0' || conn_limit < -1) /* minimum valid value */
151+
{
152+
fprintf(stderr,
153+
_("%s: invalid value for --connection-limit: %s\n"),
154+
progname, optarg);
155+
exit(1);
156+
}
148157
break;
149158
case 'P':
150159
pwprompt = true;
@@ -305,8 +314,8 @@ main(int argc, char *argv[])
305314
appendPQExpBufferStr(&sql, " REPLICATION");
306315
if (replication == TRI_NO)
307316
appendPQExpBufferStr(&sql, " NOREPLICATION");
308-
if (conn_limit != NULL)
309-
appendPQExpBuffer(&sql, " CONNECTION LIMIT %s", conn_limit);
317+
if (conn_limit >= -1)
318+
appendPQExpBuffer(&sql, " CONNECTION LIMIT %d", conn_limit);
310319
if (roles.head != NULL)
311320
{
312321
SimpleStringListCell *cell;

0 commit comments

Comments
 (0)