Skip to content

Commit

Permalink
git-cvsserver: protect against NULL in crypt(3)
Browse files Browse the repository at this point in the history
Some versions of crypt(3) will return NULL when passed an unsupported
hash type (ex: OpenBSD with DES), so check for undef instead of using
it directly.

Also use this to probe the system and select a better hash function in
the tests, so it can pass successfully.

Signed-off-by: Carlo Marcelo Arenas Belón <carenas@gmail.com>
[jc: <CAPUEspjqD5zy8TLuFA96usU7FYi=0wF84y7NgOVFqegtxL9zbw@mail.gmail.com>]
Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
carenas authored and gitster committed Sep 17, 2021
1 parent a7775c7 commit bffcb4d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
5 changes: 3 additions & 2 deletions git-cvsserver.perl
Expand Up @@ -222,10 +222,11 @@
open my $passwd, "<", $authdb or die $!;
while (<$passwd>) {
if (m{^\Q$user\E:(.*)}) {
if (crypt(descramble($password), $1) eq $1) {
my $hash = crypt(descramble($password), $1);
if (defined $hash and $hash eq $1) {
$auth_ok = 1;
}
};
}
}
close $passwd;

Expand Down
7 changes: 6 additions & 1 deletion t/t9400-git-cvsserver-server.sh
Expand Up @@ -36,7 +36,12 @@ CVSWORK="$PWD/cvswork"
CVS_SERVER=git-cvsserver
export CVSROOT CVS_SERVER

PWDHASH='lac2ItudM3.KM'
if perl -e 'exit(1) if not defined crypt("", "cv")'
then
PWDHASH='lac2ItudM3.KM'
else
PWDHASH='$2b$10$t8fGvE/a9eLmfOLzsZme2uOa2QtoMYwIxq9wZA6aBKtF1Yb7FJIzi'
fi

rm -rf "$CVSWORK" "$SERVERDIR"
test_expect_success 'setup' '
Expand Down

0 comments on commit bffcb4d

Please sign in to comment.