Repository navigation
fix(hooks): do not count a printf whose format holds %n as writing nothing - #262
Conversation
…thing bash and zsh store the count of printed characters into the variable a %n operand names, so `printf x%n PATH; gh ...` set PATH to 1 and was judged read-only. Treat %n with any flags, width, precision, positional index or length as an assignment, including a %n zsh builds from \u, \U, \x or octal escapes in the format. Refs #255 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
@codex review |
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
Review summary: no blocking findings. I read the diff and traced the I did not run the tests, and zsh isn't installed in the review environment. That means I could not check the zsh-specific claims against a real shell: Possible follow-up (P3, unverified): |
|
Codex Review: Didn't find any major issues. Already looking forward to the next diff. Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
…nment
printf x%n GH_HOST set a variable gh reads without the line being judged
as changing the environment, and a brace such as printf x{%,}n PATH or
sort {-o,later/gh} turned a word into %n or -o after the read-only check.
Judge a word a brace may spread as known only at run time, and treat
printf %n, zsh's print -f, and a spreading print or printf word as setting
a variable.
Refs #255
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
@codex review |
|
Review summary: no blocking findings. I read the diff and the
🤖 Generated with Claude Code |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 2f78f1111c
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
…gnment A format or option held in a variable, such as printf "$F" GH_HOST with F='x%n', may assign a variable gh reads, so judge such a line as changing the environment, as a spreading word already is. Refs #255 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
@codex review |
|
Review summary (read-only): no blocking findings. I posted no inline comments. I read the diff and checked the following by reading the code. I could not run the tests in this environment.
Residual notes, none blocking:
|
|
Codex Review: Didn't find any major issues. Another round soon, please! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
🤖 I have created a release *beep* *boop* --- ## [0.3.1](v0.3.0...v0.3.1) (2026-11-20) ### Bug Fixes * **hooks:** do not count a printf whose format holds %n as writing nothing ([#262](#262)) ([f3a4543](f3a4543)) * **hooks:** judge gh beside commands that write nothing as gh alone ([#256](#256)) ([540bbad](540bbad)) * **hooks:** stop asking for gh calls whose target and arguments are known at hook time ([#254](#254)) ([f4aa355](f4aa355)) * **lint:** close the Rust and TypeScript items of [#196](#196) ([#259](#259)) ([1d2a81e](1d2a81e)) * **lint:** select the Go model-rule forms deferred in [#196](#196) ([#257](#257)) ([8c347fe](8c347fe)) * **lint:** widen three Python model-rule selectors deferred in [#196](#196) ([#258](#258)) ([b3fc801](b3fc801)) --- This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please). Co-authored-by: furedea-release[bot] <353651101+furedea-release[bot]@users.noreply.github.com>
概要
printf x%n PATHは PATH に1を代入するのに,#256 の「何も書かないコマンド」判定では読み取りに数えられ,printf x%n PATH; gh pr list -R furedea/agent-configが allow になっていた.書式に%n変換を持つprintfを読み取りに数えず,こうした行は確認にする.これで #256 の「記録」に残した P1(%n)の限界を閉じる.Refs #255
変更前後
printf x%n PATH; gh pr list -R furedea/agent-configprintf '%s\n' x; gh pr list -R furedea/agent-configprintf $OPT PATH /tmp; gh …(run time の書式)printf x{%,}n PATH; gh …,sort {-o,later/gh} x; gh …(ブレース展開)printf x%n GH_HOST; gh issue comment 1 -R furedea/agent-config -b ok変更
agents/hooks/lib/read_only_commands.py:writes_nothingで,printfの書式オペランド(先頭の--は飛ばす)に%n変換があれば読み取りに数えない.%nの形:%のあとにフラグ・幅・精度(-+ #0'*.と数字),位置指定($),長さ修飾子(hlLqjzt)を挟んだn.%%は文字の%として飛ばす.\u/\Uで作った%は変換になり,\x/8 進で作った%は文字のまま,nはどのエスケープから作っても変換になる.この挙動どおりに展開した書式でも判定する(bash はエスケープから変換を作らないので,bash にとっては確認が増えるだけ).agents/hooks/lib/gh_command_line.py:_writes_nothing:ブレース展開などで別の語になりうる語(Command.spreading)を run time の語と同じに扱う.printf x{%,}nやsort {-o,later/gh}は展開後に%n/-oになる(ローカルの自動セキュリティレビューの指摘)._changes_environment:printfの%n,zsh のprint -f(print -f x%n Vも代入する),print/printf の run time に決まる語や広がりうる語(printf "$F" GH_HOST,printf {-v,GH_REPO} xは-vになる)を変数の代入とみなす(自動セキュリティレビューの指摘).%nで GH_HOST を変えると-R OWNER/REPOの host が変わるため.実際の挙動の確認(bash 5.3.9,macOS の bash 3.2.57,zsh 5.9.1)
V=old; printf "<書式>" Vの後のV:x%nx%5nx%-nx%.3nx%#nx%0nx% nx%+nx%'nx%lnx%Lnx%hhnx%znx%jnx%tnx%lln%hhn以外は代入しないx%*n,x%.*n(*が引数を 1 つ取る)x%1$n,x%2$nx%%%nx%%n,x%qn,x%bnx%n,x\U00000025n,x%\x6e,x%\156,x%l\x6ex\045n,x\x25n,x\x25\x6eテスト
printf x%n PATH; gh pr list -R furedea/agent-configが修正前はallowで失敗(test_a_line_that_may_plant_a_program_or_change_path_still_asks[printf assigning PATH with %n]),writes_nothingの単体テスト 17 件も失敗.tests/hooks/test_gh_joined_read_only_lines.py:%nの行は確認,普通のprintf '%s\n' xの行は allow.tests/hooks/test_read_only_commands.py:上表で代入した書式(--付きも)は読み取りでない,%s\n・x%%n・100%%・%d items・x\045n・%s・-nは読み取り,\UFFFFFFFFのような Unicode 範囲外のエスケープでも落ちない.test_gh_joined_read_only_lines.py:printf x{%,}n PATH,sort {-o,later/gh} xの行は確認(修正前は allow で失敗).test_gh_environment.py:printf x%n GH_HOST(修正前は allow で失敗),print -f x%n GH_HOST,printf {-v,GH_REPO} other/r,printf "$F" GH_HOST(修正前は allow で失敗)の行は確認.%%判定,zsh 展開の削除,\x/8 進の%の扱い,--の扱い,8 進の桁数)はすべて検出.uv run pytest -n auto tests(6253 passed,2 skipped),ruff check,ruff format --check,ty check,deptry,vulture.範囲・前提・限界
%nだけ.zsh のcd OLD NEW,リダイレクト先のブレース展開・~+/~-,コマンドの無い文の> f,git 読み取り(feat(agent-runtime): build persistent, isolated, provider-neutral agent infrastructure #181)は範囲外.\\156のようにエスケープされたバックスラッシュの後の数字も zsh のエスケープとして展開するので,%\\156は確認になる.bash で%nなどを使う書式も確認になる.%nによる gh の読む変数の代入(changes_environment)とブレース展開は,同じ%nの取りこぼしとして本 PR で扱った.print -fはどの書式でも確認になる.printf '%s\n' "$X"のように run time の語を持つ print/printf と gh を並べた行は確認になる.ブレースなどで広がる語を持つprintf/echo/sort/sed/awk/uniq/base64は確認になる.\0NNN(4 桁)を読む」:zsh 5.9.1 でprintf 'a\0156b'はa \r 6 b,printf 'a\0045b'はa \004 5 b,V=old; printf 'x\0045n' Vで V は変わらず,\0を含めて 3 桁までと確認したため変更しない(スレッドに証拠を返信して解決).8 進で作った%は zsh でも文字のままなので,\0045が%になっても%n変換にはならない.claude-review の同じ P3 の疑問も同じ理由で変更しない.printf -v VAR fmtではassigns_a_countが-vを書式と読む」:-vは_changes_environmentが変数の代入として捕らえるので,printf -v PATH x; gh pr list -R …,printf -v X x%n PATH; gh …はどちらも確認になることを確かめた.誤った allow にならないため変更しない.🤖 Generated with Claude Code