From e242c3be7a246671308a63c4af133591fc566c67 Mon Sep 17 00:00:00 2001 From: Dmitrii Kuvaiskii Date: Fri, 27 Mar 2026 12:10:02 +0000 Subject: [PATCH] Fix teststr segfault when built with `-ftrivial-auto-var-init` * test/teststr.c -- one test case was broken and worked by accident: the apr_strtok() function was intentionally called with `str == NULL` on first invocation. This leads to an access to `*internal_state`, which is technically undefined (uninitialized pointer on the stack). Without `-ftrivial-auto-var-init`, the `*internal_state` is benign by accident: the previous test case left the pointer-on-stack with some reasonable address. However, with `-ftrivial-auto-var-init=zero`, the `*internal_state` access fails because `internal_state = NULL` (auto-initialized to zero). So the whole test segfaults. This commit comments out this broken test case and also adds a new CI workflow to cover this `-ftrivial-auto-var-init` compilation mode. --- .github/workflows/linux.yml | 3 +++ test/teststr.c | 7 ++++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/.github/workflows/linux.yml b/.github/workflows/linux.yml index 93a885f662..041ffbbc7f 100644 --- a/.github/workflows/linux.yml +++ b/.github/workflows/linux.yml @@ -87,6 +87,9 @@ jobs: notest-cflags: -Werror config: --enable-maintainer-mode --with-berkeley-db --with-dbm=db5 config-output: APU_HAVE_DB + - name: Auto-var-init + os: ubuntu-latest # requires gcc 12 or higher + notest-cflags: -ftrivial-auto-var-init=zero fail-fast: false runs-on: ${{ matrix.os }} diff --git a/test/teststr.c b/test/teststr.c index 4817ac33cc..4fd4a1e058 100644 --- a/test/teststr.c +++ b/test/teststr.c @@ -48,10 +48,15 @@ static void test_strtok(abts_case *tc, void *data) " asdf jkl; 77889909 \r\n\1\2\3Z", " \r\n\3\2\1" }, +#if 0 +/* don't do this... apr_strtok() is not supposed to be called with + * str == NULL in the first invocation, otherwise it segfaults. + */ { - NULL, /* but who cares if apr_strtok() segfaults? */ + NULL, " \t" }, +#endif #if 0 /* don't do this... you deserve to segfault */ { "a b c ",