diff options
author | Michael Paquier | 2019-08-09 02:05:14 +0000 |
---|---|---|
committer | Michael Paquier | 2019-08-09 02:05:14 +0000 |
commit | b8f2da0ac5a24f669c8d320c58646759b8fc69a5 (patch) | |
tree | dc68a064354682b5916a87224ef325f1e83c1bbf /src/backend | |
parent | 28b901f73a3924187988bfaac57d20e422a432c3 (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/backend')
-rw-r--r-- | src/backend/libpq/be-secure-common.c | 8 |
1 files changed, 3 insertions, 5 deletions
diff --git a/src/backend/libpq/be-secure-common.c b/src/backend/libpq/be-secure-common.c index 4abbef5bf19..e8f27bc7825 100644 --- a/src/backend/libpq/be-secure-common.c +++ b/src/backend/libpq/be-secure-common.c @@ -22,6 +22,7 @@ #include <sys/stat.h> #include <unistd.h> +#include "common/string.h" #include "libpq/libpq.h" #include "storage/fd.h" @@ -112,11 +113,8 @@ run_ssl_passphrase_command(const char *prompt, bool is_server_start, char *buf, goto error; } - /* strip trailing newline, including \r in case we're on Windows */ - len = strlen(buf); - 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); error: pfree(command.data); |