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 authored and jesperpedersen committed Mar 2, 2024
1 parent 3b56518 commit d9f9253
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 17 deletions.
3 changes: 2 additions & 1 deletion AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ Luca Ferrari <fluca1978@gmail.com>
Nikita Bugrovsky <nbugrovs@redhat.com>
Lawrence Wu <lawrence910426@gmail.com>
Yongting You <2010youy01@gmail.com>
Ashutosh Sharma <ash2003sharma@gmail.com>
Ashutosh Sharma <ash2003sharma@gmail.com>
Henrique de Carvalho <decarv.henrique@gmail.com>
22 changes: 6 additions & 16 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,10 +669,7 @@ main(int argc, char** argv)
pgagroal_stop_logging();
pgagroal_destroy_shared_memory(shmem, size);

if (do_free)
{
free(password);
}
free(password);

if (verbose)
{
Expand Down

0 comments on commit d9f9253

Please sign in to comment.