summaryrefslogtreecommitdiff
path: root/src/interfaces/libpq/fe-connect.c
diff options
context:
space:
mode:
authorMichael Paquier <michael@paquier.xyz>2019-08-09 11:05:14 +0900
committerMichael Paquier <michael@paquier.xyz>2019-08-09 11:05:14 +0900
commitb8f2da0ac5a24f669c8d320c58646759b8fc69a5 (patch)
treedc68a064354682b5916a87224ef325f1e83c1bbf /src/interfaces/libpq/fe-connect.c
parent28b901f73a3924187988bfaac57d20e422a432c3 (diff)
Refactor logic to remove trailing CR/LF characters from strings
b654714 has reworked the way trailing CR/LF characters are removed from strings. This commit introduces a new routine in common/string.c and refactors the code so as the logic is in a single place, mostly. Author: Michael Paquier Reviewed-by: Bruce Momjian Discussion: https://postgr.es/m/20190801031820.GF29334@paquier.xyz
Diffstat (limited to 'src/interfaces/libpq/fe-connect.c')
-rw-r--r--src/interfaces/libpq/fe-connect.c9
1 files changed, 3 insertions, 6 deletions
diff --git a/src/interfaces/libpq/fe-connect.c b/src/interfaces/libpq/fe-connect.c
index d262b57021d..fa5af18ffac 100644
--- a/src/interfaces/libpq/fe-connect.c
+++ b/src/interfaces/libpq/fe-connect.c
@@ -73,6 +73,7 @@ static int ldapServiceLookup(const char *purl, PQconninfoOption *options,
#include "common/ip.h"
#include "common/link-canary.h"
#include "common/scram-common.h"
+#include "common/string.h"
#include "mb/pg_wchar.h"
#include "port/pg_bswap.h"
@@ -6911,12 +6912,8 @@ passwordFromFile(const char *hostname, const char *port, const char *dbname,
if (fgets(buf, sizeof(buf), fp) == NULL)
break;
- len = strlen(buf);
-
- /* 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';
+ /* strip trailing newline and carriage return */
+ len = pg_strip_crlf(buf);
if (len == 0)
continue;