aboutsummaryrefslogtreecommitdiff
path: root/ui-log.c
diff options
context:
space:
mode:
authorJason A. Donenfeld <Jason@zx2c4.com>2026-04-13 19:02:31 +0200
committerJason A. Donenfeld <Jason@zx2c4.com>2026-04-13 19:04:38 +0200
commit829eb0711305e8946fa2f4a1c57c43354f35e208 (patch)
treeaf4ba00100ac7ce398f6654c693a2f367945d443 /ui-log.c
parent0d8e5fbc31e1082063bfb5155c35b7869721152b (diff)
downloadcgit-829eb0711305e8946fa2f4a1c57c43354f35e208.tar.xz
cache: truncate lock file before filling
lock_slot() opens the lock file with O_RDWR|O_CREAT but without O_TRUNC. If a previous cgit process was killed between lock_slot() and unlock_slot() (e.g. by a CGI timeout or OOM), the stale lock file remains on disk with the old content, and the kernel releases the fcntl lock. The next process to claim the same cache slot then opens this stale lock file, acquires the fcntl lock, writes its key and generated content on top of the old bytes. If the new response is shorter than what was previously in the file, trailing bytes from the old response survive beyond the end of the new content. fstat() in fill_slot() reports the total file size (including the stale tail), and print_slot() faithfully sends all of it -- producing a response that is the correct page followed by a fragment of whatever previously occupied that lock file. Fix this by truncating the lock file after acquiring the lock and before writing the new key. Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Diffstat (limited to 'ui-log.c')
0 files changed, 0 insertions, 0 deletions