8000 createuser: fix parsing of --connection-limit argument · tinyms/postgres@ca902ad · GitHub
[go: up one dir, main page]

Skip to content

Commit ca902ad

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 bdd19e4 commit ca902ad

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
@@ -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
char newuser_buf[128];
@@ -89,6 +89,8 @@ main(int argc, char *argv[])
8989
while ((c = getopt_long(argc, argv, "h:p:U:g:wWedDsSaArRiIlLc:PE",
9090
long_options, &optindex)) != -1)
9191
{
92+
char *endptr;
93+
9294
switch (c)
9395
{
9496
case 'h':
@@ -145,7 +147,14 @@ main(int argc, char *argv[])
145147
login = TRI_NO;
146148
break;
147149
case 'c':
148-
conn_limit = pg_strdup(optarg);
150+
conn_limit = strtol(optarg, &endptr, 10);
151+
if (*endptr != '\0' || conn_limit < -1) /* minimum valid value */
152+
{
153+
fprintf(stderr,
154+
_("%s: invalid value for --connection-limit: %s\n"),
155+
progname, optarg);
156+
exit(1);
157+
}
149158
break;
150159
case 'P':
151160
pwprompt = true;
@@ -300,8 +309,8 @@ main(int argc, char *argv[])
300309
appendPQExpBufferStr(&sql, " REPLICATION");
301310
if (replication == TRI_NO)
302311
appendPQExpBufferStr(&sql, " NOREPLICATION");
303-
if (conn_limit != NULL)
304-
appendPQExpBuffer(&sql, " CONNECTION LIMIT %s", conn_limit);
312+
if (conn_limit >= -1)
313+
appendPQExpBuffer(&sql, " CONNECTION LIMIT %d", conn_limit);
305314
if (roles.head != NULL)
306315
{
307316
SimpleStringListCell *cell;

0 commit comments

Comments
 (0)
0