{"thread":{"id":"58605","subject":"bug in Git.pm handling unsafe repos","startedAt":"2022-10-12T00:40:46Z","lastAt":"2022-10-12T00:40:46Z","messageCount":1,"participants":["Hank Leininger"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"464645","messageId":"20221011182607.f1113fff-9333-427d-ba45-741a78fa6040@korelogic.com","threadId":"58605","inReplyTo":null,"subject":"bug in Git.pm handling unsafe repos","fromName":"Hank Leininger","fromEmail":"hlein@korelogic.com","sentAt":"2022-10-12T00:33:26Z","receivedAt":"2022-10-12T00:40:46Z","isPatch":false,"sender":{"key":"hlein@korelogic.com","avatar":null},"body":"Git.pm dies with a syntax error rather than a meaningful message when\ntold to open a repo that the new logic deems unsafe.\n\nWhat did you do before the bug happened? (Steps to reproduce your issue)\n\nCreate a bare repo as a different user, without registering it as \"safe\".\nThen attempt to open that repo using the perl Git.pm module:\n\n  patsy@foo ~/tmp/test-repo-bare.git $ id\n  uid=986(patsy) gid=986(patsy) groups=986(patsy)\n  patsy@foo ~/tmp/test-repo-bare.git $ ls -la\n  total 36\n  drwxrwxr-x  6 hlein hlein 4096 Oct 11 17:02 .\n  drwxrwx--- 12 patsy hlein 4096 Oct 11 17:04 ..\n  -rw-rw-r--  1 hlein hlein   23 Oct 11 17:02 HEAD\n  -rw-rw-r--  1 hlein hlein   66 Oct 11 17:02 config\n  -rw-rw-r--  1 hlein hlein   73 Oct 11 17:02 description\n  drwxrwxr-x  2 hlein hlein 4096 Oct 11 17:02 hooks\n  drwxrwxr-x  2 hlein hlein 4096 Oct 11 17:02 info\n  drwxrwxr-x  4 hlein hlein 4096 Oct 11 17:02 objects\n  drwxrwxr-x  4 hlein hlein 4096 Oct 11 17:02 refs\n\n  patsy@foo ~/tmp/test-repo-bare.git $ perl -MGit -e 'my $repo = Git->repository'\n  Can't use string (\"/home/patsy/tmp/test-repo-bare.g\"...) as a HASH ref while \"strict refs\" in use at /usr/lib64/perl5/vendor_perl/5.36/Error.pm line 234.\n\nWhat did you expect to happen? (Expected behavior)\n\nA meaningful error because the repo is not safe to open, similar to what\n'git status' produces:\n\n  patsy@foo ~/tmp/test-repo-bare.git $ git status\n  fatal: detected dubious ownership in repository at '/home/patsy/tmp/test-repo-bare.git'\n  ...\n\nWhat happened instead? (Actual behavior)\n\n  Can't use string (\"/home/patsy/tmp/test-repo-bare.g\"...) as a HASH ref while \"strict refs\" in use at /usr/lib64/perl5/vendor_perl/5.36/Error.pm line 234. \n\nWhat's different between what you expected and what actually happened?\n\nPerl syntax error when trying to generate the meaningful error.\n\nAnything else you want to add:\n\nOpening a \"safe\" repo (owned by the user, or marked safe in gitconfig)\nof course does not error, which is as expected.\n\nIt seems that this call at Git.pm line 181:\n\n  try {   \n    $dir = $search->command_oneline(['rev-parse', '--git-dir'],\n                                    STDERR => 0);\n  } catch Git::Error::Command with {\n    $dir = undef;\n  };\n\n...discards errors so that it just moves on to the next test, but in\nthis case what it discards would be new and interesting:\n\n  [pid  1448] write(2, \"fatal: detected dubious ownershi\"..., 212) = 212\n\n...which is the first chance to catch the problem. It doesn't die right\naway; I suspect this just sends the logic down a previously untested path.\n\nPlease review the rest of the bug report below.\nYou can delete any lines you don't wish to share.\n\n\n[System Info]\ngit version:\ngit version 2.38.0\ncpu: x86_64\nno commit associated with this build\nsizeof-long: 8\nsizeof-size_t: 8\nshell-path: /bin/sh\nuname: Linux 5.10.mumble\ncompiler info: gnuc: 11.3\nlibc info: glibc: 2.35\n$SHELL (typically, interactive shell): /bin/bash\n\n\n[Enabled Hooks]\nnot run from a git repository - no hooks to show\n\nThanks,\n\n-- \n\nHank Leininger <hlein@korelogic.com>\n9606 3BF9 B593 4CBC E31A  A384 6200 F6E3 781E 3DD7\n"}]}