Fix teststr segfault when built with -ftrivial-auto-var-init#71
Fix teststr segfault when built with -ftrivial-auto-var-init#71dimakuv wants to merge 1 commit intoapache:trunkfrom
-ftrivial-auto-var-init#71Conversation
|
@dimakuv could you try adding another CI workflow to cover this compilation mode? |
|
@notroj Looking at the current CI workflow (Linux example), I see that there are two knobs that the apr project uses:
I cannot use the first knob, because there's no way to specify arbitrary compilation flags as inputs to the configure script (at least I don't see a way after inspecting I also cannot use the second knob ( So the only option I see is to introduce a new variable diff --git a/.github/workflows/linux.yml b/.github/workflows/linux.yml
@@ -87,10 +87,14 @@ 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
+ cflags: -ftrivial-auto-var-init=zero
fail-fast: false
runs-on: ${{ matrix.os }}
env:
+ CFLAGS: ${{ matrix.cflags }}
NOTEST_CFLAGS: ${{ matrix.notest-cflags }}
name: ${{ matrix.name }}
steps:
Is the above what you would recommend to add? |
|
* 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.
54ae6d1 to
e242c3b
Compare
Thanks, I didn't realize this (the name misled me, and I incorrectly read the comments about this envvar the first time). Fixed now. |
|
Perfect, thanks a lot! |
The apr test suite has a test error (segfault) when built with
-ftrivial-auto-var-init=zero:Debug stack trace:
Root cause analysis:
apr/test/teststr.c
Line 52 in e461da5
apr/test/teststr.c
Line 81 in e461da5
apr_strtok(str, sep, internal_state)function must not be called withstr == NULLin the first invocation. However the test does exactly this, and this leads to an access to*internal_state, which is technically undefined (uninitialized pointer on the stack).-ftrivial-auto-var-init=zero, the*internal_stateis 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_stateaccess fails becauseinternal_state = NULL(auto-initialized to zero). So the whole test segfaults.Reproducer
Note that
-ftrivial-auto-var-init=zeroflag was introduced in GCC v12.Testing the fix