Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 8fa8e01

Browse filesBrowse 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 b048f55 commit 8fa8e01
Copy full SHA for 8fa8e01

File tree

Expand file treeCollapse file tree

1 file changed

+13
-4
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+13
-4
lines changed

‎src/bin/scripts/createuser.c

Copy file name to clipboardExpand all lines: src/bin/scripts/createuser.c
+13-4Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ main(int argc, char *argv[])
6060
enum trivalue prompt_password = TRI_DEFAULT;
6161
bool echo = false;
6262
bool interactive = false;
63-
char *conn_limit = NULL;
63+
int conn_limit = -2; /* less than minimum valid value */
6464
bool pwprompt = false;
6565
char *newpassword = NULL;
6666
char newuser_buf[128];
@@ -88,6 +88,8 @@ main(int argc, char *argv[])
8888
while ((c = getopt_long(argc, argv, "h:p:U:g:wWedDsSrRiIlLc:PE",
8989
long_options, &optindex)) != -1)
9090
{
91+
char *endptr;
92+
9193
switch (c)
9294
{
9395
case 'h':
@@ -142,7 +144,14 @@ main(int argc, char *argv[])
142144
login = TRI_NO;
143145
break;
144146
case 'c':
145-
conn_limit = pg_strdup(optarg);
147+
conn_limit = strtol(optarg, &endptr, 10);
148+
if (*endptr != '\0' || conn_limit < -1) /* minimum valid value */
149+
{
150+
fprintf(stderr,
151+
_("%s: invalid value for --connection-limit: %s\n"),
152+
progname, optarg);
153+
exit(1);
154+
}
146155
break;
147156
case 'P':
148157
pwprompt = true;
@@ -297,8 +306,8 @@ main(int argc, char *argv[])
297306
appendPQExpBufferStr(&sql, " REPLICATION");
298307
if (replication == TRI_NO)
299308
appendPQExpBufferStr(&sql, " NOREPLICATION");
300-
if (conn_limit != NULL)
301-
appendPQExpBuffer(&sql, " CONNECTION LIMIT %s", conn_limit);
309+
if (conn_limit >= -1)
310+
appendPQExpBuffer(&sql, " CONNECTION LIMIT %d", conn_limit);
302311
if (roles.head != NULL)
303312
{
304313
SimpleStringListCell *cell;

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.