Skip to content

Commit f9ac2b4

Browse files
committed
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. Submitted by: Dmitrii Kuvaiskii <dimakuv amazon.de> GitHub: closes #71 git-svn-id: https://svn.apache.org/repos/asf/apr/apr/trunk@1932662 13f79535-47bb-0310-9956-ffa450edef68
1 parent e461da5 commit f9ac2b4

2 files changed

Lines changed: 9 additions & 1 deletion

File tree

.github/workflows/linux.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,9 @@ jobs:
8787
notest-cflags: -Werror
8888
config: --enable-maintainer-mode --with-berkeley-db --with-dbm=db5
8989
config-output: APU_HAVE_DB
90+
- name: Auto-var-init
91+
os: ubuntu-latest # requires gcc 12 or higher
92+
notest-cflags: -ftrivial-auto-var-init=zero
9093
fail-fast: false
9194

9295
runs-on: ${{ matrix.os }}

test/teststr.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,15 @@ static void test_strtok(abts_case *tc, void *data)
4848
" asdf jkl; 77889909 \r\n\1\2\3Z",
4949
" \r\n\3\2\1"
5050
},
51+
#if 0
52+
/* don't do this... apr_strtok() is not supposed to be called with
53+
* str == NULL in the first invocation, otherwise it segfaults.
54+
*/
5155
{
52-
NULL, /* but who cares if apr_strtok() segfaults? */
56+
NULL,
5357
" \t"
5458
},
59+
#endif
5560
#if 0 /* don't do this... you deserve to segfault */
5661
{
5762
"a b c ",

0 commit comments

Comments
 (0)