]> git.ipfire.org Git - thirdparty/shadow.git/commit
libmisc: agetpass(): Fix bug detecting truncation
authorAlejandro Colomar <alx@kernel.org>
Sun, 19 Feb 2023 18:26:56 +0000 (19:26 +0100)
committerIker Pedrosa <ikerpedrosam@gmail.com>
Mon, 20 Feb 2023 11:16:01 +0000 (12:16 +0100)
commit5c5dc756419e1d3cad63c66c4bb803eadf1074fd
tree69c0ddde9681c40b906fedfad13277c9290743c6
parentbaae5b4a06c905d9f52ed1f922a0d7d0625d11cf
libmisc: agetpass(): Fix bug detecting truncation

On 2/19/23 18:09, David Mudrich wrote:
> I am working on a RAM based Linux OS from source, and try to use
> latest versions of all software.  I found shadow needs libbsd's
> readpassphrase(3) as superior alternative to getpass(3).  While
> considering if I a) include libbsd, or include libbsd's code of
> readpassphrase(3) into shadow, found, that libbsd's readpassphrase(3)
> never returns \n or \r
> <https://cgit.freedesktop.org/libbsd/tree/src/readpassphrase.c>
> line 122, while agetpass() uses a check for \n in agetpass.c line 108.
> I assume it always fails.

Indeed, it always failed.  I made a mistake when writing agetpass(),
assuming that readpassphrase(3) would keep newlines.

>
> I propose a check of len == PASS_MAX - 1, with false positive error for
> exactly PASS_MAX - 1 long passwords.

Instead, I added an extra byte to the allocation to allow a maximum
password length of PASS_MAX (which is the maximum for getpass(3), which
we're replacing.

While doing that, I notice that my previous implementation also had
another bug (minor): The maximum password length was PASS_MAX - 1
instead of PASS_MAX.  That's also fixed in this commit.

Reported-by: David Mudrich <dmudrich@gmx.de>
Fixes: 155c9421b935 ("libmisc: agetpass(), erase_pass(): Add functions for getting passwords safely")
Cc: Iker Pedrosa <ipedrosa@redhat.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
libmisc/agetpass.c