Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix infinite loop when an empty or blank password is given #303

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions bin/pgut/pgut-fe.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ setup_workers(int num_workers)
if (username && username[0])
appendStringInfo(&buf, "user=%s ", username);
if (password && password[0])
appendStringInfo(&buf, "password=%s ", password);
appendStringInfo(&buf, "password='%s' ", password);

if (workers.conns == NULL)
{
Expand Down Expand Up @@ -169,7 +169,7 @@ reconnect(int elevel)
if (username && username[0])
appendStringInfo(&buf, "user=%s ", username);
if (password && password[0])
appendStringInfo(&buf, "password=%s ", password);
appendStringInfo(&buf, "password='%s' ", password);

connection = pgut_connect(buf.data, prompt_password, elevel);
conn2 = pgut_connect(buf.data, prompt_password, elevel);
Expand Down
19 changes: 13 additions & 6 deletions bin/pgut/pgut.c
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,9 @@ prompt_for_password(void)
buf = pgut_malloc(BUFSIZE);
memcpy(buf, passwdbuf, sizeof(char)*BUFSIZE);
} else {
buf = simple_prompt("Password: ", BUFSIZE, false);
do {
buf = simple_prompt("Password: ", BUFSIZE, false);
} while (strlen(buf) == 0);
have_passwd = true;
passwdbuf = pgut_malloc(BUFSIZE);
memcpy(passwdbuf, buf, sizeof(char)*BUFSIZE);
Expand All @@ -459,8 +461,11 @@ prompt_for_password(void)
if (have_passwd) {
memcpy(buf, passwdbuf, sizeof(char)*BUFSIZE);
} else {
if (buf != NULL)
simple_prompt("Password: ", buf, BUFSIZE, false);
if (buf != NULL) {
do {
simple_prompt("Password: ", buf, BUFSIZE, false);
} while (strlen(buf) == 0);
}
have_passwd = true;
passwdbuf = pgut_malloc(BUFSIZE);
memcpy(passwdbuf, buf, sizeof(char)*BUFSIZE);
Expand All @@ -470,7 +475,9 @@ prompt_for_password(void)
buf = pgut_malloc(BUFSIZE);
memcpy(buf, passwdbuf, sizeof(char)*BUFSIZE);
} else {
buf = simple_prompt("Password: ", false);
do {
buf = simple_prompt("Password: ", false);
} while (strlen(buf) == 0);
have_passwd = true;
passwdbuf = pgut_malloc(BUFSIZE);
memcpy(passwdbuf, buf, sizeof(char)*BUFSIZE);
Expand Down Expand Up @@ -500,7 +507,7 @@ pgut_connect(const char *info, YesNo prompt, int elevel)
passwd = prompt_for_password();
initStringInfo(&add_pass);
appendStringInfoString(&add_pass, info);
appendStringInfo(&add_pass, " password=%s ", passwd);
appendStringInfo(&add_pass, " password='%s' ", passwd);
}
else
{
Expand Down Expand Up @@ -552,7 +559,7 @@ pgut_connect(const char *info, YesNo prompt, int elevel)
else
initStringInfo(&add_pass);
appendStringInfoString(&add_pass, info);
appendStringInfo(&add_pass, " password=%s ", passwd);
appendStringInfo(&add_pass, " password='%s' ", passwd);
continue;
}

Expand Down