已关闭
[Bug]: Dereference of null pointer #42
pineapplebaby创建于  7月16日关闭于  16 天前
pineapplebaby
7月16日 创建

感谢对OpenHarmony社区的支持与关注,欢迎反馈缺陷。

发生了什么问题?

framework/algorithm/common/image_openclsetup.cpp(约 129–160 行)

ChooseDevice 先把 idxDevices[platform] 设为 (cl_uint)-1,再在设备列表里挑选。若 numDevices 为 0,循环不进入,下标保持 -1。随后只要 deviceName 非空,就会在校验「是否选到设备」之前,用 devices[...][idxDevices[...]] 去调 clGetDeviceInfo:

pCtx->idxDevices[pCtx->idxPlatforms] = (cl_uint)(-1);
for (cl_uint i = 0; i < pCtx->numDevices[pCtx->idxPlatforms]; i++) {
    /* 选中设备并写入 idxDevices */
}
if (deviceName != nullptr) {
    status = clGetDeviceInfo(
        pCtx->devices[pCtx->idxPlatforms][pCtx->idxDevices[pCtx->idxPlatforms]],
        CL_DEVICE_NAME, deviceLength, deviceName, nullptr);
    /* 此时 idx 可能仍是 (cl_uint)-1 */
}
CHECK_AND_RETURN_RET_LOG(!((cl_uint)(-1) == pCtx->idxDevices[pCtx->idxPlatforms]),
    CL_DEVICE_NOT_FOUND, "[GPU]: There is no  GPU to use. exit.");

期望行为是什么?

未选到设备时直接返回 CL_DEVICE_NOT_FOUND,不要调用 clGetDeviceInfo。只有下标有效时才查询 CL_DEVICE_NAME。

如何复现该缺陷

把「无 GPU」检查提前到 deviceName 查询之前:

CHECK_AND_RETURN_RET_LOG(
    !((cl_uint)(-1) == pCtx->idxDevices[pCtx->idxPlatforms]),
    CL_DEVICE_NOT_FOUND, "[GPU]: There is no  GPU to use. exit.");
if (deviceName != nullptr) {
    status = clGetDeviceInfo(
        pCtx->devices[pCtx->idxPlatforms][pCtx->idxDevices[pCtx->idxPlatforms]],
        CL_DEVICE_NAME, deviceLength, deviceName, nullptr);
    /* ... */
}
return status;

其他补充信息

版本或分支信息

likedislike
openharmony_ci
openharmony_ci成员
7月16日 评论:

感谢提交Issue!关于Issue的交互操作,请访问OpenHarmony社区支持命令清单。如果有问题,请联系 [@peng5233](https://gitcode.com/peng5233) [@zhanghongran](https://gitcode.com/zhanghongran) 。如果需要调整订阅PR、Issue的变更状态,请访问链接


Thanks for submitting the issue. For more commands, please visit OpenHarmony Command List. If you have any questions, please refer to committer gitcode for help. If you need to change the subscription of a Pull Request or Issue, please visit the link.

likedislike
openharmony_ciopenharmony_ci成员
7月16日 添加了label:waiting_for_assign
adamyliuadamyliu
23 天前 关联了pull request:[Bug]: Dereference of null pointer
openharmony_ciopenharmony_ci成员
16 天前 关闭了 issue
openharmony_ciopenharmony_ci成员
16 天前 issue状态由 待办的 改变为 已完成
adamyliuadamyliu
10 小时前 关联了pull request:[Bug]: Dereference of null pointer