diff --git a/frontend/src/pwgen.c b/frontend/src/pwgen.c index 8a8fad9..b5f77b2 100644 --- a/frontend/src/pwgen.c +++ b/frontend/src/pwgen.c @@ -40,11 +40,24 @@ static const char PASSWD_SYMBOLS[] = #define PASSPHRASE_BUFFSIZE (SLUNKCRYPT_PWDLEN_MAX + 2U) +static void trim_end_of_line(char *const buffer) +{ + size_t length; + for (length = strlen(buffer); length > 0U; --length) + { + const char last = buffer[length - 1U]; + if ((last != '\r') && (last != '\n') && (last != '\f')) + { + break; + } + } + buffer[length] = '\0'; +} + char *read_passphrase(const CHR *const file_name) { - size_t str_len = 0U; - CHR *passphrase_path = NULL; char *buffer = NULL; + CHR *passphrase_path = NULL; FILE *passphrase_file = NULL; if ((!file_name) || (!file_name[0U])) @@ -84,11 +97,7 @@ char *read_passphrase(const CHR *const file_name) buffer[0U] = '\0'; goto finish; } - str_len = strlen(buffer); - while ((str_len > 0U) && ((buffer[str_len - 1U] == '\r') || (buffer[str_len - 1U] == '\n'))) - { - buffer[--str_len] = '\0'; - } + trim_end_of_line(buffer); } while (!buffer[0U]);