git/builtin
Patrick Steinhardt e7fb2ca945 builtin/blame: fix out-of-bounds write with blank boundary commits
When passing the `-b` flag to git-blame(1), then any blamed boundary
commits which were marked as uninteresting will not get their actual
commit ID printed, but will instead be replaced by a couple of spaces.

The flag can lead to an out-of-bounds write as though when combined with
`--abbrev=` when the abbreviation length is longer than `GIT_MAX_HEXSZ`
as we simply use memset(3p) on that array with the user-provided length
directly. The result is most likely that we segfault.

An obvious fix would be to cull `length` to `GIT_MAX_HEXSZ` many bytes.
But when the underlying object ID is SHA1, and if the abbreviated length
exceeds the SHA1 length, it would cause us to print more bytes than
desired, and the result would be misaligned.

Instead, fix the bug by computing the length via strlen(3p). This makes
us write as many bytes as the formatted object ID requires and thus
effectively limits the length of what we may end up printing to the
length of its hash. If `--abbrev=` asks us to abbreviate to something
shorter than the full length of the underlying hash function it would be
handled by the call to printf(3p) correctly.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2025-01-10 06:56:55 -08:00
..
add.c global: trivial conversions to fix `-Wsign-compare` warnings 2024-12-06 20:20:04 +09:00
am.c diff.h: fix index used to loop through unsigned integer 2024-12-06 20:20:03 +09:00
annotate.c Merge branch 'jc/a-commands-without-the-repo' 2024-10-25 14:02:36 -04:00
apply.c builtin: remove USE_THE_REPOSITORY_VARIABLE from builtin.h 2024-09-13 14:32:24 -07:00
archive.c archive: remove the_repository global variable 2024-10-11 09:37:18 -07:00
bisect.c global: mark code units that generate warnings with `-Wsign-compare` 2024-12-06 20:20:02 +09:00
blame.c builtin/blame: fix out-of-bounds write with blank boundary commits 2025-01-10 06:56:55 -08:00
branch.c global: trivial conversions to fix `-Wsign-compare` warnings 2024-12-06 20:20:04 +09:00
bugreport.c builtin: remove USE_THE_REPOSITORY_VARIABLE from builtin.h 2024-09-13 14:32:24 -07:00
bundle.c builtin: pass repository to sub commands 2024-11-26 10:36:08 +09:00
cat-file.c global: mark code units that generate warnings with `-Wsign-compare` 2024-12-06 20:20:02 +09:00
check-attr.c builtin: remove USE_THE_REPOSITORY_VARIABLE from builtin.h 2024-09-13 14:32:24 -07:00
check-ignore.c builtin: remove USE_THE_REPOSITORY_VARIABLE from builtin.h 2024-09-13 14:32:24 -07:00
check-mailmap.c Merge branch 'jc/pass-repo-to-builtins' 2024-09-23 10:35:09 -07:00
check-ref-format.c builtin: remove USE_THE_REPOSITORY for those without the_repository 2024-09-13 14:33:30 -07:00
checkout--worker.c global: mark code units that generate warnings with `-Wsign-compare` 2024-12-06 20:20:02 +09:00
checkout-index.c global: mark code units that generate warnings with `-Wsign-compare` 2024-12-06 20:20:02 +09:00
checkout.c global: mark code units that generate warnings with `-Wsign-compare` 2024-12-06 20:20:02 +09:00
clean.c global: mark code units that generate warnings with `-Wsign-compare` 2024-12-06 20:20:02 +09:00
clone.c global: mark code units that generate warnings with `-Wsign-compare` 2024-12-06 20:20:02 +09:00
column.c builtin: remove USE_THE_REPOSITORY_VARIABLE from builtin.h 2024-09-13 14:32:24 -07:00
commit-graph.c builtin: pass repository to sub commands 2024-11-26 10:36:08 +09:00
commit-tree.c builtin: remove USE_THE_REPOSITORY_VARIABLE from builtin.h 2024-09-13 14:32:24 -07:00
commit.c global: mark code units that generate warnings with `-Wsign-compare` 2024-12-06 20:20:02 +09:00
config.c builtin: pass repository to sub commands 2024-11-26 10:36:08 +09:00
count-objects.c Merge branch 'jc/pass-repo-to-builtins' 2024-09-23 10:35:09 -07:00
credential-cache--daemon.c builtin: remove USE_THE_REPOSITORY_VARIABLE from builtin.h 2024-09-13 14:32:24 -07:00
credential-cache.c Merge branch 'rj/cygwin-exit' 2024-11-01 12:53:19 -04:00
credential-store.c builtin: remove USE_THE_REPOSITORY_VARIABLE from builtin.h 2024-09-13 14:32:24 -07:00
credential.c builtin: remove USE_THE_REPOSITORY_VARIABLE from builtin.h 2024-09-13 14:32:24 -07:00
describe.c global: mark code units that generate warnings with `-Wsign-compare` 2024-12-06 20:20:02 +09:00
diagnose.c builtin: remove USE_THE_REPOSITORY for those without the_repository 2024-09-13 14:33:30 -07:00
diff-files.c global: mark code units that generate warnings with `-Wsign-compare` 2024-12-06 20:20:02 +09:00
diff-index.c global: mark code units that generate warnings with `-Wsign-compare` 2024-12-06 20:20:02 +09:00
diff-tree.c diff.h: fix index used to loop through unsigned integer 2024-12-06 20:20:03 +09:00
diff.c global: mark code units that generate warnings with `-Wsign-compare` 2024-12-06 20:20:02 +09:00
difftool.c global: trivial conversions to fix `-Wsign-compare` warnings 2024-12-06 20:20:04 +09:00
fast-export.c global: mark code units that generate warnings with `-Wsign-compare` 2024-12-06 20:20:02 +09:00
fast-import.c global: mark code units that generate warnings with `-Wsign-compare` 2024-12-06 20:20:02 +09:00
fetch-pack.c global: mark code units that generate warnings with `-Wsign-compare` 2024-12-06 20:20:02 +09:00
fetch.c global: mark code units that generate warnings with `-Wsign-compare` 2024-12-06 20:20:02 +09:00
fmt-merge-msg.c Merge branch 'jc/pass-repo-to-builtins' 2024-09-23 10:35:09 -07:00
for-each-ref.c Merge branch 'jc/pass-repo-to-builtins' 2024-09-23 10:35:09 -07:00
for-each-repo.c global: trivial conversions to fix `-Wsign-compare` warnings 2024-12-06 20:20:04 +09:00
fsck.c builtin: remove USE_THE_REPOSITORY_VARIABLE from builtin.h 2024-09-13 14:32:24 -07:00
fsmonitor--daemon.c global: mark code units that generate warnings with `-Wsign-compare` 2024-12-06 20:20:02 +09:00
gc.c global: mark code units that generate warnings with `-Wsign-compare` 2024-12-06 20:20:02 +09:00
get-tar-commit-id.c builtin: remove USE_THE_REPOSITORY for those without the_repository 2024-09-13 14:33:30 -07:00
grep.c global: mark code units that generate warnings with `-Wsign-compare` 2024-12-06 20:20:02 +09:00
hash-object.c builtin: remove USE_THE_REPOSITORY_VARIABLE from builtin.h 2024-09-13 14:32:24 -07:00
help.c global: trivial conversions to fix `-Wsign-compare` warnings 2024-12-06 20:20:04 +09:00
hook.c builtin: pass repository to sub commands 2024-11-26 10:36:08 +09:00
index-pack.c global: mark code units that generate warnings with `-Wsign-compare` 2024-12-06 20:20:02 +09:00
init-db.c builtin/init-db: fix leaking directory paths 2024-11-21 08:23:45 +09:00
interpret-trailers.c trailer: spread usage of "trailer_block" language 2024-10-14 12:33:02 -04:00
log.c global: mark code units that generate warnings with `-Wsign-compare` 2024-12-06 20:20:02 +09:00
ls-files.c global: mark code units that generate warnings with `-Wsign-compare` 2024-12-06 20:20:02 +09:00
ls-remote.c builtin/ls-remote: plug leaking server options 2024-11-04 22:37:51 -08:00
ls-tree.c builtin: remove USE_THE_REPOSITORY_VARIABLE from builtin.h 2024-09-13 14:32:24 -07:00
mailinfo.c builtin: remove USE_THE_REPOSITORY_VARIABLE from builtin.h 2024-09-13 14:32:24 -07:00
mailsplit.c global: trivial conversions to fix `-Wsign-compare` warnings 2024-12-06 20:20:04 +09:00
merge-base.c builtin: remove USE_THE_REPOSITORY_VARIABLE from builtin.h 2024-09-13 14:32:24 -07:00
merge-file.c global: mark code units that generate warnings with `-Wsign-compare` 2024-12-06 20:20:02 +09:00
merge-index.c global: mark code units that generate warnings with `-Wsign-compare` 2024-12-06 20:20:02 +09:00
merge-ours.c diff.h: fix index used to loop through unsigned integer 2024-12-06 20:20:03 +09:00
merge-recursive.c builtin: remove USE_THE_REPOSITORY_VARIABLE from builtin.h 2024-09-13 14:32:24 -07:00
merge-tree.c global: trivial conversions to fix `-Wsign-compare` warnings 2024-12-06 20:20:04 +09:00
merge.c global: mark code units that generate warnings with `-Wsign-compare` 2024-12-06 20:20:02 +09:00
mktag.c builtin: remove USE_THE_REPOSITORY_VARIABLE from builtin.h 2024-09-13 14:32:24 -07:00
mktree.c builtin: remove USE_THE_REPOSITORY_VARIABLE from builtin.h 2024-09-13 14:32:24 -07:00
multi-pack-index.c builtin: pass repository to sub commands 2024-11-26 10:36:08 +09:00
mv.c global: mark code units that generate warnings with `-Wsign-compare` 2024-12-06 20:20:02 +09:00
name-rev.c global: mark code units that generate warnings with `-Wsign-compare` 2024-12-06 20:20:02 +09:00
notes.c builtin: pass repository to sub commands 2024-11-26 10:36:08 +09:00
pack-objects.c global: mark code units that generate warnings with `-Wsign-compare` 2024-12-06 20:20:02 +09:00
pack-redundant.c global: trivial conversions to fix `-Wsign-compare` warnings 2024-12-06 20:20:04 +09:00
pack-refs.c diff.h: fix index used to loop through unsigned integer 2024-12-06 20:20:03 +09:00
patch-id.c builtin/patch-id: fix type of `get_one_patchid()` 2024-12-06 20:20:05 +09:00
prune-packed.c builtin: remove USE_THE_REPOSITORY for those without the_repository 2024-09-13 14:33:30 -07:00
prune.c global: mark code units that generate warnings with `-Wsign-compare` 2024-12-06 20:20:02 +09:00
pull.c global: trivial conversions to fix `-Wsign-compare` warnings 2024-12-06 20:20:04 +09:00
push.c global: trivial conversions to fix `-Wsign-compare` warnings 2024-12-06 20:20:04 +09:00
range-diff.c diff.h: fix index used to loop through unsigned integer 2024-12-06 20:20:03 +09:00
read-tree.c builtin: remove USE_THE_REPOSITORY_VARIABLE from builtin.h 2024-09-13 14:32:24 -07:00
rebase.c global: mark code units that generate warnings with `-Wsign-compare` 2024-12-06 20:20:02 +09:00
receive-pack.c global: mark code units that generate warnings with `-Wsign-compare` 2024-12-06 20:20:02 +09:00
reflog.c diff.h: fix index used to loop through unsigned integer 2024-12-06 20:20:03 +09:00
refs.c Merge branch 'kn/pass-repo-to-builtin-sub-sub-commands' 2024-12-04 10:14:47 +09:00
remote-ext.c builtin: remove USE_THE_REPOSITORY for those without the_repository 2024-09-13 14:33:30 -07:00
remote-fd.c builtin: remove USE_THE_REPOSITORY for those without the_repository 2024-09-13 14:33:30 -07:00
remote.c global: mark code units that generate warnings with `-Wsign-compare` 2024-12-06 20:20:02 +09:00
repack.c global: mark code units that generate warnings with `-Wsign-compare` 2024-12-06 20:20:02 +09:00
replace.c refs: allow passing flags when setting up a transaction 2024-11-21 07:59:14 +09:00
replay.c global: mark code units that generate warnings with `-Wsign-compare` 2024-12-06 20:20:02 +09:00
rerere.c global: trivial conversions to fix `-Wsign-compare` warnings 2024-12-06 20:20:04 +09:00
reset.c diff.h: fix index used to loop through unsigned integer 2024-12-06 20:20:03 +09:00
rev-list.c global: mark code units that generate warnings with `-Wsign-compare` 2024-12-06 20:20:02 +09:00
rev-parse.c global: mark code units that generate warnings with `-Wsign-compare` 2024-12-06 20:20:02 +09:00
revert.c diff.h: fix index used to loop through unsigned integer 2024-12-06 20:20:03 +09:00
rm.c global: mark code units that generate warnings with `-Wsign-compare` 2024-12-06 20:20:02 +09:00
send-pack.c builtin/send-pack: fix leaking list of push options 2024-09-30 11:23:09 -07:00
shortlog.c diff.h: fix index used to loop through unsigned integer 2024-12-06 20:20:03 +09:00
show-branch.c global: mark code units that generate warnings with `-Wsign-compare` 2024-12-06 20:20:02 +09:00
show-index.c global: mark code units that generate warnings with `-Wsign-compare` 2024-12-06 20:20:02 +09:00
show-ref.c builtin: remove USE_THE_REPOSITORY_VARIABLE from builtin.h 2024-09-13 14:32:24 -07:00
sparse-checkout.c global: mark code units that generate warnings with `-Wsign-compare` 2024-12-06 20:20:02 +09:00
stash.c global: trivial conversions to fix `-Wsign-compare` warnings 2024-12-06 20:20:04 +09:00
stripspace.c builtin: remove USE_THE_REPOSITORY_VARIABLE from builtin.h 2024-09-13 14:32:24 -07:00
submodule--helper.c global: trivial conversions to fix `-Wsign-compare` warnings 2024-12-06 20:20:04 +09:00
symbolic-ref.c builtin: remove USE_THE_REPOSITORY_VARIABLE from builtin.h 2024-09-13 14:32:24 -07:00
tag.c global: mark code units that generate warnings with `-Wsign-compare` 2024-12-06 20:20:02 +09:00
unpack-file.c builtin: remove USE_THE_REPOSITORY_VARIABLE from builtin.h 2024-09-13 14:32:24 -07:00
unpack-objects.c global: mark code units that generate warnings with `-Wsign-compare` 2024-12-06 20:20:02 +09:00
update-index.c global: mark code units that generate warnings with `-Wsign-compare` 2024-12-06 20:20:02 +09:00
update-ref.c global: mark code units that generate warnings with `-Wsign-compare` 2024-12-06 20:20:02 +09:00
update-server-info.c builtin: remove USE_THE_REPOSITORY_VARIABLE from builtin.h 2024-09-13 14:32:24 -07:00
upload-archive.c Merge branch 'jc/pass-repo-to-builtins' 2024-09-23 10:35:09 -07:00
upload-pack.c builtin: remove USE_THE_REPOSITORY for those without the_repository 2024-09-13 14:33:30 -07:00
var.c global: trivial conversions to fix `-Wsign-compare` warnings 2024-12-06 20:20:04 +09:00
verify-commit.c builtin: remove USE_THE_REPOSITORY_VARIABLE from builtin.h 2024-09-13 14:32:24 -07:00
verify-pack.c builtin: remove USE_THE_REPOSITORY_VARIABLE from builtin.h 2024-09-13 14:32:24 -07:00
verify-tag.c Merge branch 'jc/pass-repo-to-builtins' 2024-09-23 10:35:09 -07:00
worktree.c global: mark code units that generate warnings with `-Wsign-compare` 2024-12-06 20:20:02 +09:00
write-tree.c Merge branch 'jc/pass-repo-to-builtins' 2024-09-23 10:35:09 -07:00