[meta] release-notes.sh: replace control characters in commit subjects

Commit subjects were printed as-is,
so escape sequences, carriage returns,
and other control characters in a subject reached the terminal during `make release-notes` and `make release`,
where they could hide or rewrite lines of the notes being reviewed,
and were then written verbatim into the bump commit and the release tag.
A tab in a subject also corrupted the tab-separated intermediate file.

Subjects are now filtered as they are read from `git log`,
replacing C0 controls, DEL,
and UTF-8-encoded C1 controls with `?`.
They are replaced rather than removed so that the bytes on either side cannot join into a new control character,
and so the change stays visible in the notes.
The section `grep` now matches bytes,
because in a UTF-8 locale GNU grep stops printing matches at a line that is not valid UTF-8,
which silently dropped bullets.
Lowercasing a subject to find its category now works on bytes too,
because in a UTF-8 locale BSD `tr` stops at a byte that is not valid UTF-8.

Discovered by Anthropic's OSS Scanner, as bug ANT-2026-INF3JLG6; the scanner correctly classified it as not a vulnerability.
This commit is contained in:
Jordan Harband committed 2026-10-23 08:53:58 -07:00
1 parent d639676bb0
commit 013b291d36
2 files changed
+96 -3

No files matched your search

+9 -3
View File
@@ -66,14 +66,19 @@ fi
: "${REPO_SLUG:=nvm-sh/nvm}"
TAB="$(printf '\t')"
# U+0080 through U+009F, as UTF-8 bytes
C1_CONTROLS="$(printf '\302[\200-\237]')"
COMMITS_FILE="$(mktemp)" || exit 1
GH_ERR_FILE="$(mktemp)" || exit 1
trap 'rm -f "${COMMITS_FILE}" "${GH_ERR_FILE}"' EXIT
# each line: <section key> TAB <sha> TAB <bullet text>, in git log order
git log --no-merges --format='%H %s' "${PREV_REF}..${END_REF}" | while IFS=' ' read -r SHA SUBJECT; do
LOWERED="$(printf '%s' "${SUBJECT}" | tr '[:upper:]' '[:lower:]')"
# control characters in a subject would corrupt the terminal and the tab-separated output;
# replacing them (rather than removing them) keeps the bytes around them from joining into another one
git log --no-merges --format='%H %s' "${PREV_REF}..${END_REF}" | LC_ALL=C sed "s/[[:cntrl:]]/?/g;s/${C1_CONTROLS}/?/g" | while IFS=' ' read -r SHA SUBJECT; do
# match bytes: in a UTF-8 locale, BSD tr stops at a byte that is not valid UTF-8
LOWERED="$(printf '%s' "${SUBJECT}" | LC_ALL=C tr '[:upper:]' '[:lower:]')"
STRIPPED="${SUBJECT#\[*\] }"
case "${LOWERED}" in
v[0-9]*.[0-9]*.[0-9]*)
@@ -115,7 +120,8 @@ print_section() {
return 0
fi
printf '\n%s\n\n' "$2"
grep "^$1${TAB}" "${COMMITS_FILE}" | while IFS="${TAB}" read -r _KEY SHA TEXT; do
# match bytes: in a UTF-8 locale, GNU grep stops printing matches at a line that is not valid UTF-8
LC_ALL=C grep "^$1${TAB}" "${COMMITS_FILE}" | while IFS="${TAB}" read -r _KEY SHA TEXT; do
REF=''
case "${TEXT}" in
*'(#'[0-9]*')') ;; # the subject already carries a reference