Fix bug with pg_enc and pg_md5.
authorTatsuo Ishii <ishii@sraoss.co.jp>
Fri, 18 Mar 2022 11:52:07 +0000 (20:52 +0900)
committerTatsuo Ishii <ishii@sraoss.co.jp>
Fri, 18 Mar 2022 11:52:07 +0000 (20:52 +0900)
When these commands are invoked with "-i" option (read username/password
pairs from a file), it did not create proper entries in pool_passwd.
This bug was introduced by the commit:
https://git.postgresql.org/gitweb/?p=pgpool2.git;a=commit;h=441bde41767fe3bccad513735f946dd2dec5059b

Bug reported in https://www.pgpool.net/mantisbt/view.php?id=747

src/tools/pgenc/pg_enc.c
src/tools/pgmd5/pg_md5.c

index 988870cfb6874527d6fb2ee42e13f4f043804602..e39ddafc1f13c079c7500783c50273a337b68b46 100644 (file)
@@ -5,7 +5,7 @@
  * pgpool: a language independent connection pool server for PostgreSQL
  * written by Tatsuo Ishii
  *
- * Copyright (c) 2003-2021     PgPool Global Development Group
+ * Copyright (c) 2003-2022     PgPool Global Development Group
  *
  * Permission to use, copy, modify, and distribute this software and
  * its documentation for any purpose and without fee is hereby
@@ -372,7 +372,7 @@ process_input_file(char *conf_file, char *input_file, char *key, bool updatepass
                        fprintf(stderr, "LINE#%02d: input exceeds maximum username length %d\n",line_count,  MAX_USER_NAME_LEN);
                        goto clear_buffer;
                }
-               strncpy(username, buf, sizeof(username) - 1);
+               strncpy(username, buf, pch - buf - 1);
 
                if (strlen(pch) >= sizeof(password))
                {
index 70f27461543306c08f762b3fb3f233a0554f152d..25d36a4d271eb6ca1639bb38feb79e675df1debd 100644 (file)
@@ -5,7 +5,7 @@
  * pgpool: a language independent connection pool server for PostgreSQL
  * written by Tatsuo Ishii
  *
- * Copyright (c) 2003-2021     PgPool Global Development Group
+ * Copyright (c) 2003-2022     PgPool Global Development Group
  *
  * Permission to use, copy, modify, and distribute this software and
  * its documentation for any purpose and without fee is hereby
@@ -273,7 +273,7 @@ update_pool_passwd_from_file(char *conf_file, char *input_file, bool md5auth)
                        fprintf(stdout, "input exceeds maximum username length %d\n\n", MAX_USER_NAME_LEN);
                        continue;
                }
-               strncpy(username, buf, sizeof(username) - 1);
+               strncpy(username, buf, pch - buf - 1);
 
                if (strlen(pch) >= sizeof(password))
                {