Skip to content

[Bug]: COM_SET_OPTION returns OK for malformed or unsupported option values #25743

Closed

Description

@Ariznawlll

Is there an existing issue for the same bug?

  • I have checked the existing issues.

Branch Name

main-based checkout (main)

Commit ID

e538e203ad47ebf0506a424fe93aed61290c4061

Actual Behavior

MysqlCmdExecutor.ExecRequest calls handleSetOption, constructs an error response when it fails, and then unconditionally returns a new OK response:

err = handleSetOption(ses, data)
if err != nil {
    resp = NewGeneralErrorResponse(COM_SET_OPTION, err)
}
return NewGeneralOkResponse(COM_SET_OPTION), nil

Consequently, both a short payload and an unsupported value (anything other than 0 or 1) are acknowledged as successful.

A white-box test calling ExecRequest(..., COM_SET_OPTION, []byte{2, 0}) expects ErrorResponse but receives OkResponse.

Expected Behavior

Invalid COM_SET_OPTION payloads should return the error response produced from handleSetOption; valid values 0 and 1 should continue to return OK.

Steps to Reproduce

  1. Create a minimal frontend session and command executor.
  2. Call ExecRequest with COM_SET_OPTION and payload []byte{2, 0}.
  3. Assert that the response category is ErrorResponse.

The assertion currently fails because the response category is OkResponse.

Relevant code

  • pkg/frontend/mysql_cmd_executor.go: ExecRequest COM_SET_OPTION branch
  • pkg/frontend/mysql_cmd_executor.go: handleSetOption

Activity

  1. added
    kind/bug
    on Jul 15, 2026
  2. Ariznawlll commented on Jul 15, 2026

    @Ariznawlll
    CollaboratorAuthor

    main 分支复核

    • 测试基线:当轮最新 origin/main@e538e203ad47ebf0506a424fe93aed61290c4061
    • 测试过程/用例:分别发送长度 0、1 的截断 COM_SET_OPTION payload,并发送完整但不支持的 option 值 2;断言均应返回 ErrorResponse。
    • 实际结果:三种输入都返回 category=0(OK),而不是错误响应。
    • 结论:已在该 main 基线确认仍可复现,issue 有效。
  3. added theissue type on Jul 15, 2026
  4. added this to the MO-202607 milestone on Jul 15, 2026
  5. daviszhen commented on Sep 21, 2026

    @daviszhen
    Contributor

    本地 Docker 实测复核(2026-09-21):使用从当时最新 matrixorigin/main@df41cc24fc88fefab35151b494faa928c55eacb8 构建的 mo-service,直连 CN 的 MySQL 协议端口发送原始报文;已核对容器运行进程与构建产物的 SHA-256 一致。

    对 COM_SET_OPTION 发送空 payload、1 字节 payload,以及完整但不支持的值 2、65535:4/4 均收到 MySQL ERR 20101(短包为 invalid cmd_set_option data length,不支持值为 invalid cmd_set_option data)。对有效值 0、1 的对照测试均收到 OK;测试后的新连接与 COM_PING 仍正常。

    结论:此 issue 描述的非法值误回 OK 问题在上述 main 提交上已无法复现。e2c5dc0 / PR #25750 将 handleSetOption 的错误响应改为直接返回。

  6. Ariznawlll commented on Sep 22, 2026

    @Ariznawlll
    CollaboratorAuthor

    测试版本

    • 日期:2026-09-22
    • 分支:main
    • MatrixOne commit:3727c5c5436ca136d7b0312f75bc223a11692a85
    • 部署:本地单机,1 Log / 1 TN / 1 CN

    原问题验证

    COM_SET_OPTION 对合法 option 返回 OK,对畸形 payload 或不支持的 option 返回 ERR,不再把非法请求当作成功处理。

    Happy Path 覆盖

    覆盖合法 multi-statements 开关及响应,并在每个请求后以 COM_PING 验证连接可继续使用。

    Unhappy Path 覆盖

    覆盖空 payload、单字节、超长 payload、未知 option 值等;单轮 18 个合法及畸形组合的 OK/ERR 均符合协议契约。

    白盒验证

    测试通过原始 MySQL handshake 直接构造 wire packet,不经过客户端驱动预校验,可直接命中服务端 COM_SET_OPTION payload 边界。

    回归测试

    新增 script/14_issue_regression/issue_25743_25744_25756_protocol_bounds.go 及同名 .sh 入口,已提交至 motr#199。

    测试证据

    协议场景连续执行 3 轮;本次新增 7 个 case 共执行 21 次,结果为 21/21 通过。14_issue_regression 整套执行时该场景也通过。MOTR 当前未为该分支上报远端 checks。

    测试结论

    测试通过。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

deferredkind/bug

Type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions