Suggested fix for reports/musl-regex-marksub-null.txt. Checks tre_ast_new_union's result the same way every other allocation in this function already is (see e.g. the three lines above parse_bracket_done, or the `if (!ctx->n) return REG_ESPACE;` right after every other tre_ast_new_* call in tre_parse). Without this, a failed allocation here reaches marksub() with a NULL node and marksub unconditionally dereferences it at `if (node->submatch_id >= 0)`. Against musl commit 7813e9119eb5fe681b6750b8a033a0490bca0941 (src/regex/regcomp.c). --- a/src/regex/regcomp.c +++ b/src/regex/regcomp.c @@ -1056,6 +1056,8 @@ static reg_errcode_t tre_parse(tre_parse_ctx_t *ctx) int c = *s; nunion = tre_ast_new_union(ctx->mem, nunion, nbranch); nbranch = 0; + if (!nunion) + return REG_ESPACE; if (c == '\\' && s[1] == '|') { s+=2;