Skip to content

Commit

Permalink
Fix SegFault in pgagroal-cli
Browse files Browse the repository at this point in the history
pgagroal-cli was raising segmentation fault when no command is specified, but a password is specified.
  • Loading branch information
decarv committed Mar 2, 2024
1 parent a9c4c13 commit 5a72fc2
Showing 1 changed file with 6 additions and 13 deletions.
19 changes: 6 additions & 13 deletions src/cli.c
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,6 @@ main(int argc, char** argv)
char* password = NULL;
bool verbose = false;
char* logfile = NULL;
bool do_free = true;
int c;
int option_index = 0;
size_t size;
Expand Down Expand Up @@ -218,7 +217,11 @@ main(int argc, char** argv)
username = optarg;
break;
case 'P':
password = optarg;
password = strdup(optarg);
if (password == NULL)
{
errx(1, "Error allocating memory for password");
}
break;
case 'L':
logfile = optarg;
Expand Down Expand Up @@ -533,20 +536,10 @@ main(int argc, char** argv)
/* Password */
if (password == NULL)
{
if (password != NULL)
{
free(password);
password = NULL;
}

printf("Password : ");
password = pgagroal_get_password();
printf("\n");
}
else
{
do_free = false;
}

for (int i = 0; i < strlen(password); i++)
{
Expand Down Expand Up @@ -676,7 +669,7 @@ main(int argc, char** argv)
pgagroal_stop_logging();
pgagroal_destroy_shared_memory(shmem, size);

if (do_free)
if (password != NULL)
{
free(password);
}
Expand Down

0 comments on commit 5a72fc2

Please sign in to comment.