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

pgagroal-admin segfault when -f file is missing #145

Closed
will opened this issue Mar 16, 2021 · 1 comment
Closed

pgagroal-admin segfault when -f file is missing #145

will opened this issue Mar 16, 2021 · 1 comment
Assignees
Labels
bug Something isn't working

Comments

@will
Copy link
Contributor

will commented Mar 16, 2021

Describe the bug

Segfault when the file passed in in -f is not present.

To Reproduce

[centos ~]$ sudo -u pgagroal ls /home/pgagroal/.pgagroal
master.key
[centos ~]$ ls /etc/pgagroal/
pgagroal.conf  pgagroal_hba.conf

[centos ~]$ sudo -u pgagroal pgagroal-admin -f /etc/pgagroal/pgagroal_users.conf add-user -U postgres
Segmentation fault

Debug logs

[centos ~]$ sudo coredumpctl gdb 3448386
           PID: 3448386 (pgagroal-admin)
           UID: 990 (pgagroal)
           GID: 987 (pgagroal)
        Signal: 11 (SEGV)
     Timestamp: Tue 2021-03-16 19:02:01 UTC (40s ago)
  Command Line: pgagroal-admin -f /etc/pgagroal/pgagroal_users.conf add-user -U postgres
    Executable: /usr/bin/pgagroal-admin
 Control Group: /user.slice/user-1000.slice/session-373.scope
          Unit: session-373.scope
         Slice: user-1000.slice
       Session: 373
     Owner UID: 1000 (centos)
       Storage: /var/lib/systemd/coredump/core.pgagroal-admin.990.72d624ef3e1845de9ef0e8e920094516.3448386.1615921321000000.lz4
       Message: Process 3448386 (pgagroal-admin) of user 990 dumped core.

                Stack trace of thread 3448386:
                #0  0x00007f5a19ec72ef _IO_fgets (libc.so.6)
                #1  0x000055ad9cbf7bf9 add_user (pgagroal-admin)
                #2  0x000055ad9cbf7396 main (pgagroal-admin)
                #3  0x00007f5a19e797b3 __libc_start_main (libc.so.6)
                #4  0x000055ad9cbf750e _start (pgagroal-admin)


(gdb) bt
#0  0x00007f5a19ec72ef in fgets () from /usr/lib64/libc.so.6
#1  0x000055ad9cbf7bf9 in add_user (users_path=<optimized out>, username=0x7fffbdd3177c "postgres", password=0x0, generate_pwd=<optimized out>, pwd_length=64)
    at /usr/src/debug/pgagroal-1.2.0-1Crunchy.el8.x86_64/src/admin.c:476
#2  0x000055ad9cbf7396 in main (argc=<optimized out>, argv=0x7fffbdd30c98) at /usr/src/debug/pgagroal-1.2.0-1Crunchy.el8.x86_64/src/admin.c:208
(gdb) list
94	   printf("\n");
95	   printf("Commands:\n");
96	   printf("  master-key              Create or update the master key\n");
97	   printf("  add-user                Add a user\n");
98	   printf("  update-user             Update a user\n");
99	   printf("  remove-user             Remove a user\n");
100	   printf("  list-users              List all users\n");
101	   printf("\n");
102	   printf("pgagroal: %s\n", PGAGROAL_HOMEPAGE);
103	   printf("Report bugs: %s\n", PGAGROAL_ISSUES);

(gdb) f 1
#1  0x000055ad9cbf7bf9 in add_user (users_path=<optimized out>, username=0x7fffbdd3177c "postgres", password=0x0, generate_pwd=<optimized out>, pwd_length=64)
    at /usr/src/debug/pgagroal-1.2.0-1Crunchy.el8.x86_64/src/admin.c:476
476	   while (fgets(line, sizeof(line), users_file))
(gdb) list
471	   {
472	      goto username;
473	   }
474
475	   /* Verify */
476	   while (fgets(line, sizeof(line), users_file))
477	   {
478	      ptr = strtok(line, ":");
479	      if (!strcmp(username, ptr))
480	      {

(gdb) p users_file
$2 = (FILE *) 0x0


(gdb) f 2
#2  0x000055ad9cbf7396 in main (argc=<optimized out>, argv=0x7fffbdd30c98) at /usr/src/debug/pgagroal-1.2.0-1Crunchy.el8.x86_64/src/admin.c:208
208	            if (add_user(file_path, username, password, generate_pwd, pwd_length))
(gdb) list
203	      }
204	      else if (action == ACTION_ADD_USER)
205	      {
206	         if (file_path != NULL)
207	         {
208	            if (add_user(file_path, username, password, generate_pwd, pwd_length))
209	            {
210	               printf("Error for add-user\n");
211	               exit_code = 1;
212	            }


(gdb) p file_path
$3 = 0x7fffbdd3174e "/etc/pgagroal/pgagroal_users.conf"
(gdb) p username
$4 = 0x7fffbdd3177c "postgres"
(gdb) p password
$5 = 0x0
(gdb) p generate_pwd
$6 = false
(gdb) p pwd_length
$7 = 64
@will will added the bug Something isn't working label Mar 16, 2021
@jesperpedersen jesperpedersen self-assigned this Mar 17, 2021
@jesperpedersen
Copy link
Collaborator

Fixed the segfault, and output reason for file error.

Thanks Will !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants