Skip to content

[bsp][nuvoton] Clamp CAN receive DLC - #11725

Open
Zepp-Hanzj wants to merge 1 commit into
RT-Thread:masterfrom
Zepp-Hanzj:agent/fix-nuvoton-can-dlc-oob
Open

[bsp][nuvoton] Clamp CAN receive DLC#11725
Zepp-Hanzj wants to merge 1 commit into
RT-Thread:masterfrom
Zepp-Hanzj:agent/fix-nuvoton-can-dlc-oob

Conversation

@Zepp-Hanzj

Copy link
Copy Markdown
Contributor

Description / 描述

The nuvoton classic CAN drivers clamp the received DLC value from the hardware register in nu_can_recvmsg(), preventing out-of-bounds read/write on the fixed-size Data[8] buffer when the hardware reports an abnormal DLC (9~15).

nuvoton 经典 CAN 驱动在 nu_can_recvmsg() 中对来自硬件寄存器的接收 DLC 值做 clamp,防止当硬件报告异常 DLC(9~15)时对固定大小 Data[8] 缓冲区越界读写。

Why / 为什么需要

pmsg->len = tMsg.DLC 直接使用硬件寄存器值,随后 rt_memcpy(pmsg->data, &tMsg.Data[0], pmsg->len) 以该值作为拷贝长度。经典 CAN 的 tMsg.Datapmsg->data 都是 8 字节,若 DLC > 8 会导致越界读(tMsg.Data)和越界写(pmsg->data)。发送侧 nu_can_sendmsg 已用 IS_CAN_DLC(len) <= 8U 校验,接收侧却缺失,不对称。

How / 修改了哪些文件

  • bsp/nuvoton/libraries/m2354/rtt_port/drv_can.c: clamp DLC to sizeof(tMsg.Data)
  • bsp/nuvoton/libraries/m480/rtt_port/drv_can.c: clamp DLC to sizeof(tMsg.Data)
  • bsp/nuvoton/libraries/n9h30/rtt_port/drv_can.c: clamp DLC to sizeof(tMsg.Data)
  • bsp/nuvoton/libraries/nuc980/rtt_port/drv_can.c: clamp DLC to sizeof(tMsg.Data)

This fix mirrors the previously merged [bsp][loongson] Clamp CAN receive DLC change.

@github-actions github-actions Bot added the BSP label Aug 20, 2026
@github-actions

Copy link
Copy Markdown

👋 感谢您对 RT-Thread 的贡献!Thank you for your contribution to RT-Thread!

为确保代码符合 RT-Thread 的编码规范,请在你的仓库中执行以下步骤运行代码格式化工作流(如果格式化CI运行失败)。
To ensure your code complies with RT-Thread's coding style, please run the code formatting workflow by following the steps below (If the formatting of CI fails to run).


🛠 操作步骤 | Steps

  1. 前往 Actions 页面 | Go to the Actions page
    点击进入工作流 → | Click to open workflow →

  2. 点击 Run workflow | Click Run workflow

  • Use workflow from 保持默认分支(通常为 master
    Keep the default branch (usually master) in Use workflow from
  • branch 输入框填写 PR 分支 agent/fix-nuvoton-can-dlc-oob
    Enter PR branch agent/fix-nuvoton-can-dlc-oob in the branch field
  • 设置需排除的文件/目录(目录请以"/"结尾)
    Set files/directories to exclude (directories should end with "/")
  1. 等待工作流完成 | Wait for the workflow to complete
    格式化后的代码将作为独立提交推送至你的分支。
    The formatting changes will be pushed to your branch as a separate commit.

完成后,提交将自动更新至 agent/fix-nuvoton-can-dlc-oob 分支,关联的 Pull Request 也会同步更新。
Once completed, commits will be pushed to the agent/fix-nuvoton-can-dlc-oob branch automatically, and the related Pull Request will be updated.

如有问题欢迎联系我们,再次感谢您的贡献!💐
If you have any questions, feel free to reach out. Thanks again for your contribution!

@github-actions

Copy link
Copy Markdown

MemBrowse Memory Report

No memory changes detected for:

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant