[Bug 295086] /bin/sh undefined variable in heredoc triggers assertion

From: <bugzilla-noreply_at_freebsd.org>
Date: Thu, 07 May 2026 18:01:14 UTC
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=295086

            Bug ID: 295086
           Summary: /bin/sh undefined variable in heredoc triggers
                    assertion
           Product: Base System
           Version: 15.0-RELEASE
          Hardware: Any
                OS: Any
            Status: New
          Severity: Affects Some People
          Priority: ---
         Component: bin
          Assignee: bugs@FreeBSD.org
          Reporter: editor@callfortesting.org

More verbose: /bin/sh undefined variable reference inside of heredoc variable
assignment inside command expansion triggers assertion

This shell script triggers an assertion that probably should be caught by the
pre-processor:

#!/bin/sh
set -u
thing="$(cat << eol)"
Hello! $_some_unset_variable
eol

Output
test.sh: _some_unset_variable: parameter not set
Unsafe ckmalloc() call
Abort trap (core dumped)

bin/sh/memalloc.c
62:             badalloc("Unsafe ckmalloc() call\n");

Verified on 15.0R, 14.x AMD64, 15.1-BETA1 ARM64

Discovered by: Alexey Laurentsyeu
Verified by: Hayzam S, Jan B, Michael D

-- 
You are receiving this mail because:
You are the assignee for the bug.