]> git.ipfire.org Git - thirdparty/git.git/commit
strbuf_readlink(): avoid calling `readlink()` twice in corner-cases
authorKarsten Blees <blees@dcon.de>
Tue, 16 Dec 2025 15:33:47 +0000 (15:33 +0000)
committerJunio C Hamano <gitster@pobox.com>
Wed, 17 Dec 2025 23:21:06 +0000 (08:21 +0900)
commitac2339de65c545b23e93ecf0e10dd0c2870de8a6
tree2f51b009cb71b86d0601214c270011ea9a5c92cb
parent89d6c35322462c999fcaffb77c1d340b41df9a7a
strbuf_readlink(): avoid calling `readlink()` twice in corner-cases

The `strbuf_readlink()` function calls `readlink()`` twice if the hint
argument specifies the exact size of the link target (e.g. by passing
stat.st_size as returned by `lstat()`). This is necessary because
`readlink(..., hint) == hint` could mean that the buffer was too small.

Use `hint + 1` as buffer size to prevent this.

Signed-off-by: Karsten Blees <blees@dcon.de>
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
strbuf.c