[0143] C++ 层为 which 增加参数类型检查,修复非字符串参数导致的崩溃 - #964
Merged
Merged
Conversation
da-liii
added a commit
that referenced
this pull request
Sep 8, 2026
da-liii
added a commit
that referenced
this pull request
Sep 8, 2026
da-liii
added a commit
that referenced
this pull request
Sep 8, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
问题
(import (liii sys)) (which 123)会让 bin/gf abort(SIGABRT, exit 134,C++ 未捕获异常std::logic_error: basic_string construction from null)。根因:
src/goldfish.hpp的f_which直接s7_string(s7_car(args)),垃圾/空指针传入std::string构造函数。可选的第 2 参数path同样未检查((g_which "ls" 123)也会崩)。修复
沿用 #963(devel/0142.md)的模式,防御放在 C++ 层,并把同文件同模式的两个入口一并加固:
f_which:cmd、可选path均检查s7_is_stringf_delete_file(delete-file的底层)f_get_environment_variable(get-environment-variable的底层)测试
tests/liii/sys/which-test.scm(10 条):which 正常功能、公开入口与 C 层入口g_which的参数类型(含可选 path)、同文件两个入口的加固检查。TDD:修复前运行测试文件本身即 abort,修复后 10/10 通过bin/gf demo/crash/h02-which-public-integer.scm由 SIGABRT 变为干净的wrong-type-arg报错,验证后按惯例移除该片段备注
devel/0143.mdg_rename、g_listdir、base64 长度参数及 liii_os/liii_path/liii_hashlib 的同类静默垃圾入口)见demo/crash/README.md,建议后续批量任务处理