已合并
fix: validate pkgName length at IPC stub boundary #12462
Farmer_Joe创建于 8月27日
fix: validate pkgName length at IPC stub boundary #12462
已合并
共 4 个文件变更+8-9
| @@ -294,7 +294,7 @@ int32_t SoftBusSocketFdIsset(int32_t socketFd, SoftBusFdSet *set) | |||
| 294 | return 0; | 294 | return 0; |
| 295 | } | 295 | } |
| 296 | 296 | ||
| 297 | - if (FD_ISSET(socketFd, (fd_set *)set->fdsBits) == true) { | 297 | + if (FD_ISSET(socketFd, (fd_set *)set->fdsBits)) { |
| 298 | return 1; | 298 | return 1; |
| 299 | } else { | 299 | } else { |
| 300 | return 0; | 300 | return 0; |
| @@ -618,10 +618,6 @@ int32_t SoftBusServer::CreateServer(const char *pkgName, const char *name) | |||
| 618 | COMM_LOGE(COMM_SVC, "copy pkgName failed"); | 618 | COMM_LOGE(COMM_SVC, "copy pkgName failed"); |
| 619 | return SOFTBUS_STRCPY_ERR; | 619 | return SOFTBUS_STRCPY_ERR; |
| 620 | } | 620 | } |
| 621 | - if (strcpy_s(param.name, GENERAL_NAME_LEN, name) != EOK) { | ||
| 622 | - COMM_LOGE(COMM_SVC, "copy name failed"); | ||
| 623 | - return SOFTBUS_STRCPY_ERR; | ||
| 624 | - } | ||
| 625 | int32_t ret = SOFTBUS_OK; | 621 | int32_t ret = SOFTBUS_OK; |
| 626 | #ifdef SUPPORT_BUNDLENAME | 622 | #ifdef SUPPORT_BUNDLENAME |
| 627 | ret = FillBundleName(param.bundleName, BUNDLE_NAME_MAX); | 623 | ret = FillBundleName(param.bundleName, BUNDLE_NAME_MAX); |
| @@ -30,6 +30,7 @@ | |||
| 30 | #include "softbus_permission.h" | 30 | #include "softbus_permission.h" |
| 31 | #include "softbus_server_frame.h" | 31 | #include "softbus_server_frame.h" |
| 32 | #include "softbus_server_ipc_interface_code.h" | 32 | #include "softbus_server_ipc_interface_code.h" |
| 33 | +#include "softbus_utils.h" | ||
| 33 | #include "syspara/parameters.h" | 34 | #include "syspara/parameters.h" |
| 34 | #include "tokenid_kit.h" | 35 | #include "tokenid_kit.h" |
| 35 | #include "trans_channel_common.h" | 36 | #include "trans_channel_common.h" |
| @@ -408,7 +409,7 @@ int32_t SoftBusServerStub::SoftbusRegisterServiceInner(MessageParcel &data, Mess | |||
| 408 | return SOFTBUS_TRANS_PROXY_REMOTE_NULL; | 409 | return SOFTBUS_TRANS_PROXY_REMOTE_NULL; |
| 409 | } | 410 | } |
| 410 | const char *pkgName = data.ReadCString(); | 411 | const char *pkgName = data.ReadCString(); |
| 411 | - if (pkgName == nullptr) { | 412 | + if (!IsValidStringSafe(pkgName, PKG_NAME_SIZE_MAX)) { |
| 412 | COMM_LOGE(COMM_SVC, "SoftbusRegisterServiceInner read pkgName failed!"); | 413 | COMM_LOGE(COMM_SVC, "SoftbusRegisterServiceInner read pkgName failed!"); |
| 413 | return SOFTBUS_TRANS_PROXY_READCSTRING_FAILED; | 414 | return SOFTBUS_TRANS_PROXY_READCSTRING_FAILED; |
| 414 | } | 415 | } |
| @@ -596,7 +597,7 @@ int32_t SoftBusServerStub::CreateSessionServerInner(MessageParcel &data, Message | |||
| 596 | uint64_t callingFullTokenId = IPCSkeleton::GetCallingFullTokenID(); | 597 | uint64_t callingFullTokenId = IPCSkeleton::GetCallingFullTokenID(); |
| 597 | #endif | 598 | #endif |
| 598 | const char *pkgName = data.ReadCString(); | 599 | const char *pkgName = data.ReadCString(); |
| 599 | - if (pkgName == nullptr) { | 600 | + if (!IsValidStringSafe(pkgName, PKG_NAME_SIZE_MAX)) { |
| 600 | COMM_LOGE(COMM_SVC, "CreateSessionServerInner read pkgName failed!"); | 601 | COMM_LOGE(COMM_SVC, "CreateSessionServerInner read pkgName failed!"); |
| 601 | return SOFTBUS_TRANS_PROXY_READCSTRING_FAILED; | 602 | return SOFTBUS_TRANS_PROXY_READCSTRING_FAILED; |
| 602 | } | 603 | } |
| @@ -646,7 +647,7 @@ int32_t SoftBusServerStub::RemoveSessionServerInner(MessageParcel &data, Message | |||
| 646 | pid_t callingPid; | 647 | pid_t callingPid; |
| 647 | uint64_t timestamp = 0; | 648 | uint64_t timestamp = 0; |
| 648 | const char *pkgName = data.ReadCString(); | 649 | const char *pkgName = data.ReadCString(); |
| 649 | - if (pkgName == nullptr) { | 650 | + if (!IsValidStringSafe(pkgName, PKG_NAME_SIZE_MAX)) { |
| 650 | COMM_LOGE(COMM_SVC, "RemoveSessionServerInner read pkgName failed!"); | 651 | COMM_LOGE(COMM_SVC, "RemoveSessionServerInner read pkgName failed!"); |
| 651 | return SOFTBUS_TRANS_PROXY_READCSTRING_FAILED; | 652 | return SOFTBUS_TRANS_PROXY_READCSTRING_FAILED; |
| 652 | } | 653 | } |
| @@ -26,6 +26,7 @@ | |||
| 26 | #include "session_set_timer.h" | 26 | #include "session_set_timer.h" |
| 27 | #include "softbus_access_token_adapter.h" | 27 | #include "softbus_access_token_adapter.h" |
| 28 | #include "softbus_server_ipc_interface_code.h" | 28 | #include "softbus_server_ipc_interface_code.h" |
| 29 | +#include "softbus_utils.h" | ||
| 29 | 30 | ||
| 30 | namespace OHOS { | 31 | namespace OHOS { |
| 31 | static constexpr uint32_t DFX_TIMERS_S = 15; | 32 | static constexpr uint32_t DFX_TIMERS_S = 15; |
| @@ -101,7 +102,8 @@ int32_t SoftBusClientStub::OnClientPermissionChangeInner(MessageParcel &data, Me | |||
| 101 | 102 | ||
| 102 | const char *pkgName = data.ReadCString(); | 103 | const char *pkgName = data.ReadCString(); |
| 103 | COMM_CHECK_AND_RETURN_RET_LOGE( | 104 | COMM_CHECK_AND_RETURN_RET_LOGE( |
| 104 | - pkgName != nullptr, SOFTBUS_TRANS_PROXY_READCSTRING_FAILED, COMM_SDK, "read pkgName failed"); | 105 | + IsValidStringSafe(pkgName, PKG_NAME_SIZE_MAX), |
| 106 | + SOFTBUS_TRANS_PROXY_READCSTRING_FAILED, COMM_SDK, "read pkgName failed"); | ||
| 105 | 107 | ||
| 106 | PermissionStateChange(pkgName, state); | 108 | PermissionStateChange(pkgName, state); |
| 107 | return SOFTBUS_OK; | 109 | return SOFTBUS_OK; |