[0145] C++ 层为 g_listdir 增加参数类型检查,修复非字符串参数导致的崩溃 - #966
Merged
Merged
Conversation
This was referenced Sep 7, 2026
da-liii
force-pushed
the
da/0145/listdir-type-check
branch
from
September 8, 2026 00:43
28b8ed3 to
1a8dbc7
Compare
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.
问题
(g_listdir 99)会让 bin/gf abort(SIGABRT, exit 134),见demo/crash/c11-g_listdir-integer.scm。根因:
src/liii_os.cpp的f_listdir直接s7_string(s7_car(args)),垃圾/空指针进入std::string构造,抛出未捕获的std::logic_error。同一函数内path_s[path_N - 1]在空字符串参数时还存在越界读取(UB)。修复
沿用 #963(devel/0142.md)的模式,防御放在 C++ 层:
f_listdir入口检查s7_is_string,非字符串返回s7_wrong_type_arg_errorlast_ch改为仅在path_N > 0时取末字符,消除空字符串 UB(liii os)公开包装listdir已有检查,本修复使根环境直接调用g_listdir的代码也受保护。测试
tests/liii/os/listdir-test.scm增加 3 条 C 层入口回归测试。TDD:修复前运行测试文件本身即 abort(exit 134),修复后 7/7 通过(g_listdir 99)由 SIGABRT 变为干净的wrong-type-arg报错(exit 255),验证后按惯例移除demo/crash/c11-g_listdir-integer.scm并更新 README备注
devel/0145.md