pgpass_v1.patch
text/plain
Patch
Format: unified
Series: patch v1
| File | + | − |
|---|---|---|
| src/interfaces/libpq/fe-connect.c | 33 | 0 |
diff --git a/src/interfaces/libpq/fe-connect.c b/src/interfaces/libpq/fe-connect.c
index 408000af83..eb34d2122f 100644
--- a/src/interfaces/libpq/fe-connect.c
+++ b/src/interfaces/libpq/fe-connect.c
@@ -6949,6 +6949,7 @@ passwordFromFile(const char *hostname, const char *port, const char *dbname,
{
FILE *fp;
struct stat stat_buf;
+ int line_number = 0;
#define LINELEN NAMEDATALEN*5
char buf[LINELEN];
@@ -7014,10 +7015,42 @@ passwordFromFile(const char *hostname, const char *port, const char *dbname,
*p1,
*p2;
int len;
+ int buflen;
if (fgets(buf, sizeof(buf), fp) == NULL)
break;
+ line_number++;
+ buflen = strlen(buf);
+ if (buflen >= sizeof(buf) - 1 && buf[buflen - 1] != '\n')
+ {
+ char tmp[LINELEN];
+ int tmplen;
+
+ /*
+ * Warn if this password setting line is too long,
+ * because it's unexpectedly truncated.
+ */
+ if (buf[0] != '#')
+ fprintf(stderr,
+ libpq_gettext("WARNING: line %d too long in password file \"%s\"\n"),
+ line_number, pgpassfile);
+
+ /* eat rest of the line */
+ while (!feof(fp) && !ferror(fp))
+ {
+ if (fgets(tmp, sizeof(tmp), fp) == NULL)
+ break;
+ tmplen = strlen(tmp);
+ if (tmplen < sizeof(tmp) -1 || tmp[tmplen - 1] == '\n')
+ break;
+ }
+ }
+
+ /* ignore comments */
+ if (buf[0] == '#')
+ continue;
+
/* strip trailing newline and carriage return */
len = pg_strip_crlf(buf);