docs(skill): ban dispatch-level wl_resource type checks in request handlers - #1452
Conversation
|
Skipping CI for Draft Pull Request. |
Reviewer's guide (collapsed on small PRs)Reviewer's GuideUpdates the Treeland private Wayland protocol skill documentation to clarify that libwayland performs dispatch-level resource validation before request handlers run, while handlers remain responsible for semantic and protocol-specific checks; the review checklist now explicitly enforces this separation. Sequence diagram for libwayland request validationsequenceDiagram
participant Client
participant Libwayland
participant Handler
Client->>Libwayland: request
Libwayland->>Libwayland: validate object arguments
alt unknown id, type mismatch, or destroyed resource
Libwayland-->>Client: protocol error
else valid object arguments
Libwayland->>Handler: invoke request handler
Handler->>Handler: check semantic and protocol-specific conditions
end
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
09a9404 to
1c63bea
Compare
1. libwayland validates object arguments before a request handler runs: non-nullable args are never NULL, unknown ids, type mismatches and destroyed resources fail dispatch with a protocol error, and only allow-null args can arrive as NULL. 2. Condense the Request Handler Argument Validation section in treeland-private-wayland-protocol SKILL accordingly: handlers need no validation that a passed object matches its protocol-declared type or is still alive; the semantic-layer checks stay (cross-client ownership, inert resources, missing wrappers, value validity, allow-null args). 3. Add the matching Output Requirements checklist item. Log: codify the WM-558 lesson that libwayland already validates wl_resource arguments, so handlers need no dispatch-level type checks Influence: 1. Docs-only change, no build or runtime impact. 2. Request-handler code written per the skill should omit dispatch-level type checks. 3. Reviewers can apply the new checklist item when auditing protocol handler patches. docs(skill): 禁止请求处理函数内分发级 wl_resource 类型检查 1. libwayland 分发层在调用请求处理函数前已完成对象参数校验:非空参数不会 为 NULL,未知 id、类型不符或已销毁对象在进入处理函数前即报协议错误, 仅 allow-null 参数可为 NULL。 2. treeland-private-wayland-protocol SKILL 的 Request Handler Argument Validation 一节据此收为两段:处理函数无需再校验传入对象是否符合协议 声明类型或仍然存活,保留语义层检查(跨 client 归属、inert resource、 缺失包装对象、数值/枚举合法性、allow-null 参数判 NULL)。 3. Output Requirements 审查清单补充对应条目。 Log: 将 WM-558 经验(libwayland 已校验 wl_resource,处理函数无需重复类型检查)落实进协议 SKILL Influence: 1. 仅文档变更,不影响编译与运行。 2. 后续按该 skill 生成的协议处理代码应省略分发级类型检查。 3. 走查协议处理补丁时可使用新增审查条目。 Multica Issue: WM-561
1c63bea to
29e6413
Compare
wineee
left a comment
There was a problem hiding this comment.
评审结论:LGTM(仅文档变更,技术声明准确)
无 C++ 代码变更(净 +6 行文档),聚焦文档声明的技术正确性。
技术声明逐条核验(对照 libwayland 源码)
新增的 "Request Handler Argument Validation" 一节声明 libwayland 分发层已完成对象参数校验,已在 src/connection.c / src/wayland-server.c 中逐条验证,全部成立:
| PR 声明 | 源码依据 | 结论 |
|---|---|---|
| 非空参数不会是 NULL | wl_connection_demarshal:if (id == 0 && !arg.nullable) → EINVAL |
✅ |
| 未知 id 报协议错误 | wl_closure_lookup_objects:wl_map_lookup 为 NULL 且 id≠0 → "unknown object" |
✅ |
| 类型不符报协议错误 | !wl_interface_equal(object->interface, message->types[i]) → "invalid object ... type" |
✅ |
| 已销毁对象不再 resolve | wl_resource_destroy → wl_map_remove;zombie 检测返回 NULL |
✅ |
仅 allow-null="true" 可为 NULL |
scanner.c:880 限定 allow-null 仅对 object/string/array 有效 |
✅ |
语义层检查的保留也验证正确(treeland waylib/src/server/kernel/):
WSurface::fromHandle/WOutput::fromHandle确实判空并可能返回nullptr(if (!handle) return nullptr; ... handle->data)✅- "inert resource" 区分尤其有价值:
wlr_surface_from_resource在 wlr 对象已销毁但 client 仍持 wl_resource 时返回 NULL,这是分发层无法感知的(分发层只跟踪 wl_resource 生命周期,不管 wlr 层对象是否 inert)。
建议(均为非阻塞,可改可不改)
- 【建议】措辞微调:"Request handlers therefore need no validation that a passed object matches..." → "need not validate whether..." 更通顺。
- 【可选】补一个边界限定:"type mismatches fail dispatch" 成立的前提是协议 XML 为该 object 参数声明了具体 interface 类型。libwayland 中
wl_closure_lookup_objects仅在message->types[i] != NULL时才做wl_interface_equal检查。treeland 私有协议都声明了类型,不影响结论,但加半句限定可更严谨。 - 【可选】cross-client 措辞:服务端 object map 是 per-client 的(
client->objects),客户端 A 用客户端 B 的对象 id 会直接命中 "unknown object" 错误;真正需要wl_resource_get_client防御的是全局/共享对象(如 wlr_seat_client)归属校验。当前表述不算错,但可更精确。
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: deepin-wm, glyvut, wineee The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
将 WM-558 经验落实进 treeland 协议 SKILL:WM-561
变更内容
.agents/skills/treeland-private-wayland-protocol/SKILL.md(仅文档,净 +6 行):allow-null="true"参数可为 NULL——因此处理函数无需再校验传入对象是否符合协议声明类型或仍然存活。WSurface::fromHandle/WOutput::fromHandle判空、数值/枚举合法性、allow-null 参数判 NULL。Output Requirements审查清单补充第 5 条:请求处理函数不做分发层已完成的对象校验。依据:WM-558 / PR #1451。
Summary by Sourcery
Clarify request-handler validation responsibilities in the Treeland Wayland protocol skill.
Enhancements:
Documentation: