Merged
fix(runtime): 校验 acl.util.ptr_to_bytes 空指针参数 #5697
KaranocaVeAdd on Oct 21
fix(runtime): 校验 acl.util.ptr_to_bytes 空指针参数 #5697
Merged
Total: 2 files changed+3-0
| @@ -44,6 +44,8 @@ bytes_out = acl.util.ptr_to_bytes(ptr, size) | |||
| 44 | | --- | --- | | 44 | | --- | --- | |
| 45 | | bytes_out | bytes对象。 | | 45 | | bytes_out | bytes对象。 | |
| 46 | 46 | ||
| 47 | +当`size`大于0时,`ptr`必须为非空的有效地址;传入空地址将抛出`ValueError`。`size`为0时可传入空地址并返回空bytes。 | ||
| 48 | + | ||
| 47 | ## 注意事项 | 49 | ## 注意事项 |
| 48 | 50 | ||
| 49 | 修改示例如下: | 51 | 修改示例如下: |
| @@ -33,6 +33,7 @@ PyObject* WrapPtrToBytes(PyObject* /* self */, PyObject* args) | |||
| 33 | PyObject* bytesObj = nullptr; | 33 | PyObject* bytesObj = nullptr; |
| 34 | 34 | ||
| 35 | CHECK_NULL(PyArg_ParseTuple(args, "kk", &ptr, &size), "acl.util.ptr_to_bytes args parse failed"); | 35 | CHECK_NULL(PyArg_ParseTuple(args, "kk", &ptr, &size), "acl.util.ptr_to_bytes args parse failed"); |
| 36 | + CHECK_NULL(ptr != nullptr || size == 0, "ptr must not be null when size is nonzero", PyExc_ValueError); | ||
| 36 | 37 | ||
| 37 | bytesObj = PyBytes_FromStringAndSize(reinterpret_cast<const char*>(ptr), size); | 38 | bytesObj = PyBytes_FromStringAndSize(reinterpret_cast<const char*>(ptr), size); |
| 38 | CHECK_NULL(bytesObj, "convert c pointer to bytes failed", PyExc_ValueError); | 39 | CHECK_NULL(bytesObj, "convert c pointer to bytes failed", PyExc_ValueError); |