]> git.ipfire.org Git - thirdparty/git.git/commitdiff
t: use hash-object --literally when created malformed objects
authorJeff King <peff@peff.net>
Wed, 18 Jan 2023 20:41:56 +0000 (15:41 -0500)
committerJunio C Hamano <gitster@pobox.com>
Wed, 18 Jan 2023 20:59:44 +0000 (12:59 -0800)
Many test scripts use hash-object to create malformed objects to see how
we handle the results in various commands. In some cases we already have
to use "hash-object --literally", because it does some rudimentary
quality checks. But let's use "--literally" more consistently to
future-proof these tests against hash-object learning to be more
careful.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
13 files changed:
t/t1450-fsck.sh
t/t4054-diff-bogus-tree.sh
t/t4058-diff-duplicates.sh
t/t4212-log-corrupt.sh
t/t5302-pack-index.sh
t/t5504-fetch-receive-strict.sh
t/t5702-protocol-v2.sh
t/t6300-for-each-ref.sh
t/t7509-commit-authorship.sh
t/t7510-signed-commit.sh
t/t7528-signed-commit-ssh.sh
t/t8003-blame-corner-cases.sh
t/t9350-fast-export.sh

index de0f6d5e7fd49ca5276696833d8f9dd034a15629..fdb886dfe431f36dfc4ef6bcf24abf6827c2243d 100755 (executable)
@@ -212,7 +212,7 @@ test_expect_success 'email without @ is okay' '
 test_expect_success 'email with embedded > is not okay' '
        git cat-file commit HEAD >basis &&
        sed "s/@[a-z]/&>/" basis >bad-email &&
-       new=$(git hash-object -t commit -w --stdin <bad-email) &&
+       new=$(git hash-object --literally -t commit -w --stdin <bad-email) &&
        test_when_finished "remove_object $new" &&
        git update-ref refs/heads/bogus "$new" &&
        test_when_finished "git update-ref -d refs/heads/bogus" &&
@@ -223,7 +223,7 @@ test_expect_success 'email with embedded > is not okay' '
 test_expect_success 'missing < email delimiter is reported nicely' '
        git cat-file commit HEAD >basis &&
        sed "s/<//" basis >bad-email-2 &&
-       new=$(git hash-object -t commit -w --stdin <bad-email-2) &&
+       new=$(git hash-object --literally -t commit -w --stdin <bad-email-2) &&
        test_when_finished "remove_object $new" &&
        git update-ref refs/heads/bogus "$new" &&
        test_when_finished "git update-ref -d refs/heads/bogus" &&
@@ -234,7 +234,7 @@ test_expect_success 'missing < email delimiter is reported nicely' '
 test_expect_success 'missing email is reported nicely' '
        git cat-file commit HEAD >basis &&
        sed "s/[a-z]* <[^>]*>//" basis >bad-email-3 &&
-       new=$(git hash-object -t commit -w --stdin <bad-email-3) &&
+       new=$(git hash-object --literally -t commit -w --stdin <bad-email-3) &&
        test_when_finished "remove_object $new" &&
        git update-ref refs/heads/bogus "$new" &&
        test_when_finished "git update-ref -d refs/heads/bogus" &&
@@ -245,7 +245,7 @@ test_expect_success 'missing email is reported nicely' '
 test_expect_success '> in name is reported' '
        git cat-file commit HEAD >basis &&
        sed "s/ </> </" basis >bad-email-4 &&
-       new=$(git hash-object -t commit -w --stdin <bad-email-4) &&
+       new=$(git hash-object --literally -t commit -w --stdin <bad-email-4) &&
        test_when_finished "remove_object $new" &&
        git update-ref refs/heads/bogus "$new" &&
        test_when_finished "git update-ref -d refs/heads/bogus" &&
@@ -258,7 +258,7 @@ test_expect_success 'integer overflow in timestamps is reported' '
        git cat-file commit HEAD >basis &&
        sed "s/^\\(author .*>\\) [0-9]*/\\1 18446744073709551617/" \
                <basis >bad-timestamp &&
-       new=$(git hash-object -t commit -w --stdin <bad-timestamp) &&
+       new=$(git hash-object --literally -t commit -w --stdin <bad-timestamp) &&
        test_when_finished "remove_object $new" &&
        git update-ref refs/heads/bogus "$new" &&
        test_when_finished "git update-ref -d refs/heads/bogus" &&
@@ -269,7 +269,7 @@ test_expect_success 'integer overflow in timestamps is reported' '
 test_expect_success 'commit with NUL in header' '
        git cat-file commit HEAD >basis &&
        sed "s/author ./author Q/" <basis | q_to_nul >commit-NUL-header &&
-       new=$(git hash-object -t commit -w --stdin <commit-NUL-header) &&
+       new=$(git hash-object --literally -t commit -w --stdin <commit-NUL-header) &&
        test_when_finished "remove_object $new" &&
        git update-ref refs/heads/bogus "$new" &&
        test_when_finished "git update-ref -d refs/heads/bogus" &&
@@ -292,7 +292,7 @@ test_expect_success 'tree object with duplicate entries' '
                        git cat-file tree $T &&
                        git cat-file tree $T
                ) |
-               git hash-object -w -t tree --stdin
+               git hash-object --literally -w -t tree --stdin
        ) &&
        test_must_fail git fsck 2>out &&
        test_i18ngrep "error in tree .*contains duplicate file entries" out
@@ -426,7 +426,7 @@ test_expect_success 'tag with incorrect tag name & missing tagger' '
        This is an invalid tag.
        EOF
 
-       tag=$(git hash-object -t tag -w --stdin <wrong-tag) &&
+       tag=$(git hash-object --literally -t tag -w --stdin <wrong-tag) &&
        test_when_finished "remove_object $tag" &&
        echo $tag >.git/refs/tags/wrong &&
        test_when_finished "git update-ref -d refs/tags/wrong" &&
@@ -558,7 +558,7 @@ test_expect_success 'rev-list --verify-objects with commit graph (parent)' '
 test_expect_success 'force fsck to ignore double author' '
        git cat-file commit HEAD >basis &&
        sed "s/^author .*/&,&/" <basis | tr , \\n >multiple-authors &&
-       new=$(git hash-object -t commit -w --stdin <multiple-authors) &&
+       new=$(git hash-object --literally -t commit -w --stdin <multiple-authors) &&
        test_when_finished "remove_object $new" &&
        git update-ref refs/heads/bogus "$new" &&
        test_when_finished "git update-ref -d refs/heads/bogus" &&
@@ -573,7 +573,7 @@ test_expect_success 'fsck notices blob entry pointing to null sha1' '
        (git init null-blob &&
         cd null-blob &&
         sha=$(printf "100644 file$_bz$_bzoid" |
-              git hash-object -w --stdin -t tree) &&
+              git hash-object --literally -w --stdin -t tree) &&
          git fsck 2>out &&
          test_i18ngrep "warning.*null sha1" out
        )
@@ -583,7 +583,7 @@ test_expect_success 'fsck notices submodule entry pointing to null sha1' '
        (git init null-commit &&
         cd null-commit &&
         sha=$(printf "160000 submodule$_bz$_bzoid" |
-              git hash-object -w --stdin -t tree) &&
+              git hash-object --literally -w --stdin -t tree) &&
          git fsck 2>out &&
          test_i18ngrep "warning.*null sha1" out
        )
@@ -648,7 +648,7 @@ test_expect_success 'NUL in commit' '
                git commit --allow-empty -m "initial commitQNUL after message" &&
                git cat-file commit HEAD >original &&
                q_to_nul <original >munged &&
-               git hash-object -w -t commit --stdin <munged >name &&
+               git hash-object --literally -w -t commit --stdin <munged >name &&
                git branch bad $(cat name) &&
 
                test_must_fail git -c fsck.nulInCommit=error fsck 2>warn.1 &&
@@ -794,8 +794,8 @@ test_expect_success 'fsck errors in packed objects' '
        git cat-file commit HEAD >basis &&
        sed "s/</one/" basis >one &&
        sed "s/</foo/" basis >two &&
-       one=$(git hash-object -t commit -w one) &&
-       two=$(git hash-object -t commit -w two) &&
+       one=$(git hash-object --literally -t commit -w one) &&
+       two=$(git hash-object --literally -t commit -w two) &&
        pack=$(
                {
                        echo $one &&
index 294fb5531372d597a5a551b40e66437d7599e766..05c88f8cdf01d98b61eacff08b32cb57320e7d3b 100755 (executable)
@@ -10,7 +10,7 @@ test_expect_success 'create bogus tree' '
        bogus_tree=$(
                printf "100644 fooQ$name" |
                q_to_nul |
-               git hash-object -w --stdin -t tree
+               git hash-object --literally -w --stdin -t tree
        )
 '
 
index 54614b814dbc858e15fd82b8bc563ab9aae5fae8..2501c89c1c91ec7ddc02f4e285aa4c10c32b98f6 100755 (executable)
@@ -29,7 +29,7 @@ make_tree () {
                make_tree_entry "$1" "$2" "$3"
                shift; shift; shift
        done |
-       git hash-object -w -t tree --stdin
+       git hash-object --literally -w -t tree --stdin
 }
 
 # this is kind of a convoluted setup, but matches
index 30a219894bb45f2655596fe02e8a7d001a35eabd..e89e1f54b6caed2e97d04aaf4672a0491a398acf 100755 (executable)
@@ -10,7 +10,7 @@ test_expect_success 'setup' '
 
        git cat-file commit HEAD |
        sed "/^author /s/>/>-<>/" >broken_email.commit &&
-       git hash-object -w -t commit broken_email.commit >broken_email.hash &&
+       git hash-object --literally -w -t commit broken_email.commit >broken_email.hash &&
        git update-ref refs/heads/broken_email $(cat broken_email.hash)
 '
 
@@ -46,7 +46,7 @@ test_expect_success 'git log --format with broken author email' '
 munge_author_date () {
        git cat-file commit "$1" >commit.orig &&
        sed "s/^\(author .*>\) [0-9]*/\1 $2/" <commit.orig >commit.munge &&
-       git hash-object -w -t commit commit.munge
+       git hash-object --literally -w -t commit commit.munge
 }
 
 test_expect_success 'unparsable dates produce sentinel value' '
index b0095ab41d30aadda45c7dd6e812fd0a5f40ab26..59e9e77223b3e25d07d2dd7052e7674221c8a78d 100755 (executable)
@@ -263,7 +263,7 @@ tag guten tag
 This is an invalid tag.
 EOF
 
-       tag=$(git hash-object -t tag -w --stdin <wrong-tag) &&
+       tag=$(git hash-object -t tag -w --stdin --literally <wrong-tag) &&
        pack1=$(echo $tag $sha | git pack-objects tag-test) &&
        echo remove tag object &&
        thirtyeight=${tag#??} &&
index ac4099ca8931930989eece26fa735e2f6c00bbc3..88d3c56750accc7376614f0fda48d85ddf298cc6 100755 (executable)
@@ -138,7 +138,7 @@ This commit object intentionally broken
 EOF
 
 test_expect_success 'setup bogus commit' '
-       commit="$(git hash-object -t commit -w --stdin <bogus-commit)"
+       commit="$(git hash-object --literally -t commit -w --stdin <bogus-commit)"
 '
 
 test_expect_success 'fsck with no skipList input' '
index b33cd4afca3d021f1f8f38393521589243ae95fb..e4db7513f42192895e33e7eec431c73bec0007d8 100755 (executable)
@@ -1114,7 +1114,7 @@ test_expect_success 'packfile-uri with transfer.fsckobjects fails on bad object'
 
        This commit object intentionally broken
        EOF
-       BOGUS=$(git -C "$P" hash-object -t commit -w --stdin <bogus-commit) &&
+       BOGUS=$(git -C "$P" hash-object -t commit -w --stdin --literally <bogus-commit) &&
        git -C "$P" branch bogus-branch "$BOGUS" &&
 
        echo my-blob >"$P/my-blob" &&
index fa38b874416220d3d3c39ee48a99ad53b94dc2df..b02a30d8e8be500c79fdf6d50e1495ab97d6dc90 100755 (executable)
@@ -606,7 +606,7 @@ test_expect_success 'create tag without tagger' '
        git tag -a -m "Broken tag" taggerless &&
        git tag -f taggerless $(git cat-file tag taggerless |
                sed -e "/^tagger /d" |
-               git hash-object --stdin -w -t tag)
+               git hash-object --literally --stdin -w -t tag)
 '
 
 test_atom refs/tags/taggerless type 'commit'
index 21c668f75ed7345430f88f65b7e9072a873b9c42..5d890949f75b5acb4ef9334a41c080ece60c1653 100755 (executable)
@@ -105,7 +105,7 @@ test_expect_success '--amend option with empty author' '
 test_expect_success '--amend option with missing author' '
        git cat-file commit Initial >tmp &&
        sed "s/author [^<]* </author </" tmp >malformed &&
-       sha=$(git hash-object -t commit -w malformed) &&
+       sha=$(git hash-object --literally -t commit -w malformed) &&
        test_when_finished "remove_object $sha" &&
        git checkout $sha &&
        test_when_finished "git checkout Initial" &&
index 8593b7e3cb8d9aa0c4badeef4273ed406cecc9ca..bc7a31ba3e7fc4c0611c23f60470fcb392cdd424 100755 (executable)
@@ -202,7 +202,7 @@ test_expect_success GPG 'detect fudged signature with NUL' '
        git cat-file commit seventh-signed >raw &&
        cat raw >forged2 &&
        echo Qwik | tr "Q" "\000" >>forged2 &&
-       git hash-object -w -t commit forged2 >forged2.commit &&
+       git hash-object --literally -w -t commit forged2 >forged2.commit &&
        test_must_fail git verify-commit $(cat forged2.commit) &&
        git show --pretty=short --show-signature $(cat forged2.commit) >actual2 &&
        grep "BAD signature from" actual2 &&
index f47e99517983163e0bbb3fce9c35800270fe4e28..065f78063629cbfad15e9360836544da34a16484 100755 (executable)
@@ -270,7 +270,7 @@ test_expect_success GPGSSH 'detect fudged signature with NUL' '
        git cat-file commit seventh-signed >raw &&
        cat raw >forged2 &&
        echo Qwik | tr "Q" "\000" >>forged2 &&
-       git hash-object -w -t commit forged2 >forged2.commit &&
+       git hash-object --literally -w -t commit forged2 >forged2.commit &&
        test_must_fail git verify-commit $(cat forged2.commit) &&
        git show --pretty=short --show-signature $(cat forged2.commit) >actual2 &&
        grep "${GPGSSH_BAD_SIGNATURE}" actual2 &&
index d751d48b7dae6a3e007d5eb19f92cd41eb445065..8bcd39e81bfb7f28768c988caf16f27773460b4e 100755 (executable)
@@ -201,7 +201,7 @@ committer David Reiss <dreiss@facebook.com> 1234567890 +0000
 
 some message
 EOF
-  COMMIT=$(git hash-object -t commit -w badcommit) &&
+  COMMIT=$(git hash-object --literally -t commit -w badcommit) &&
   git --no-pager blame $COMMIT -- uno >/dev/null
 '
 
index ff21a12ee6e4eb1557eca22bb60ab2e01aa6b909..26c25c0eb2ba57fa90c682950fda4899329474f8 100755 (executable)
@@ -373,7 +373,7 @@ EOF
 
 test_expect_success 'cope with tagger-less tags' '
 
-       TAG=$(git hash-object -t tag -w tag-content) &&
+       TAG=$(git hash-object --literally -t tag -w tag-content) &&
        git update-ref refs/tags/sonnenschein $TAG &&
        git fast-export -C -C --signed-tags=strip --all > output &&
        test $(grep -c "^tag " output) = 4 &&