git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 2/3] git-cvsserver: protect against NULL in crypt(3)

From
Carlo Marcelo Arenas Belón <carenas@gmail.com>
Date
Sep 15, 2021, 08:09 UTC
Message-ID
<20210915080948.11891-3-carenas@gmail.com>
In-Reply-To
<20210915080948.11891-1-carenas@gmail.com>

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>
---
 git-cvsserver.perl              | 7 ++++---
 t/t9400-git-cvsserver-server.sh | 7 ++++++-
 2 files changed, 10 insertions(+), 4 deletions(-)
diff --git a/git-cvsserver.perl b/git-cvsserver.perl
index 4c93b5d099..8e7c34a235 100755
--- a/git-cvsserver.perl
+++ b/git-cvsserver.perl
@@ -222,10 +222,11 @@
         open my $passwd, "<", $authdb or die $!;
         while (<$passwd>) {
             if (m{^\Q$user\E:(.*)}) {
-                if (crypt(descramble($password), $1) eq $1) {
-                    $auth_ok = 1;
+                my $hash = crypt(descramble($password), $1);
+                if (defined $hash) {
+                    $auth_ok = 1 if $hash eq $1;
                 }
-            };
+            }
         }
         close $passwd;
 
diff --git a/t/t9400-git-cvsserver-server.sh b/t/t9400-git-cvsserver-server.sh
index 59b40359c7..17f988edd2 100755
--- a/t/t9400-git-cvsserver-server.sh
+++ b/t/t9400-git-cvsserver-server.sh
@@ -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' '
-- 
2.33.0.481.g26d3bed244
Previous: Carlo Marcelo Arenas BelónNext: Junio C Hamano
Message 3 of 7 in “cvsserver: correctly validate pserver passwords”
  1. 0/3 cvsserver: correctly validate pserver passwordsCarlo Marcelo Arenas Belón, Sep 15, 2021
  2. 1/3 git-cvsserver: use crypt correctly to compare password hashesCarlo Marcelo Arenas Belón, Sep 15, 2021
  3. 2/3 git-cvsserver: protect against NULL in crypt(3)Carlo Marcelo Arenas Belón, Sep 15, 2021
  4. Junio C HamanoSep 16, 2021
  5. Carlo ArenasSep 16, 2021
  6. Junio C HamanoSep 17, 2021
  7. 3/3 Documentation: cleanup git-cvsserverCarlo Marcelo Arenas Belón, Sep 15, 2021

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.