diff options
Diffstat (limited to 'src/interfaces/libpq/fe-connect.c')
-rw-r--r-- | src/interfaces/libpq/fe-connect.c | 23 |
1 files changed, 11 insertions, 12 deletions
diff --git a/src/interfaces/libpq/fe-connect.c b/src/interfaces/libpq/fe-connect.c index d70cf1f9484..a329ebbf93a 100644 --- a/src/interfaces/libpq/fe-connect.c +++ b/src/interfaces/libpq/fe-connect.c @@ -5020,6 +5020,8 @@ parseServiceFile(const char *serviceFile, while ((line = fgets(buf, sizeof(buf), f)) != NULL) { + int len; + linenr++; if (strlen(line) >= sizeof(buf) - 1) @@ -5032,16 +5034,17 @@ parseServiceFile(const char *serviceFile, return 2; } - /* ignore EOL at end of line */ - if (strlen(line) && line[strlen(line) - 1] == '\n') - line[strlen(line) - 1] = 0; + /* ignore whitespace at end of line, especially the newline */ + len = strlen(line); + while (len > 0 && isspace((unsigned char) line[len - 1])) + line[--len] = '\0'; - /* ignore leading blanks */ + /* ignore leading whitespace too */ while (*line && isspace((unsigned char) line[0])) line++; /* ignore comments and empty lines */ - if (strlen(line) == 0 || line[0] == '#') + if (line[0] == '\0' || line[0] == '#') continue; /* Check for right groupname */ @@ -6910,14 +6913,10 @@ passwordFromFile(const char *hostname, const char *port, const char *dbname, len = strlen(buf); - /* Remove trailing newline */ - if (len > 0 && buf[len - 1] == '\n') - { + /* Remove trailing newline, including \r in case we're on Windows */ + while (len > 0 && (buf[len - 1] == '\n' || + buf[len - 1] == '\r')) buf[--len] = '\0'; - /* Handle DOS-style line endings, too, even when not on Windows */ - if (len > 0 && buf[len - 1] == '\r') - buf[--len] = '\0'; - } if (len == 0) continue; |