npm

Nihal's Password Manager
git clone git://git.nihaljere.xyz/npm
Log | Files | Refs | README | LICENSE

commit 0258fb173a481c0033c13a290bd955921da2174e
parent 3e45997f5a233a0081988aecff7cc379a87d081f
Author: Nihal Jere <nihal@nihaljere.xyz>
Date:   Fri, 30 Jun 2023 09:07:59 -0500

get_password: end input at EOF and truncate trailing newline

Diffstat:
Mutil.c | 11++++++-----
1 file changed, 6 insertions(+), 5 deletions(-)

diff --git a/util.c b/util.c @@ -29,11 +29,12 @@ get_password(FILE *f, char *buf) char *ptr = buf; while (ptr - buf < PASSWORD_MAX_LEN) { ret = fgetc(f); - if (ret == EOF) - return -1; - - if (ret == '\n') - return ptr - buf; + if (ret == EOF) { + if (ptr > buf && *(ptr - 1) == '\n') + return ptr - buf - 1; + else + return ptr - buf; + } *(ptr++) = ret; }