From c5620fafa4c873bf1e79b4008aa3a0aa152154a3 Mon Sep 17 00:00:00 2001 From: Bryce Kwon Date: Sat, 17 Oct 2026 12:53:15 -1000 Subject: Find libc's write when git writes first A Lua build replaces write, and git can write before cmd_main reaches cgit_init_filters, as it does when GIT_TRACE2 is set, which called through a null pointer and crashed every request. --- source/filter.c | 4 ++++ tests/t0201-filters.sh | 8 ++++++++ 2 files changed, 12 insertions(+) diff --git a/source/filter.c b/source/filter.c index 43ba70a..f2dfe12 100644 --- a/source/filter.c +++ b/source/filter.c @@ -166,6 +166,10 @@ void cgit_init_filters(void) */ ssize_t write(int fd, const void *buf, size_t count) { + // Git can write before cmd_main reaches cgit_init_filters, to a trace + // target for one, so libc's write may still need looking up here. + if (!libc_write) + cgit_init_filters(); if (fd != STDOUT_FILENO || !filter_write) return libc_write(fd, buf, count); return filter_write(current_write_filter, buf, count); diff --git a/tests/t0201-filters.sh b/tests/t0201-filters.sh index 1ffb973..3987bdc 100755 --- a/tests/t0201-filters.sh +++ b/tests/t0201-filters.sh @@ -163,4 +163,12 @@ test_expect_success CGIT_LUA 'a lua filter that writes while loading still rende grep "" tmp ' +# A Lua build replaces write, and git writes its trace before cgit has run a +# line of its own. +test_expect_success CGIT_LUA 'git can trace before the filters are set up' ' + CGIT_CONFIG="$PWD/cgitrc" GIT_TRACE2="$PWD/trace2.out" QUERY_STRING="url=foo/" cgit >tmp && + grep "" tmp && + test -s trace2.out +' + test_done -- cgit