From 9809d427e75e759e0de5404892b51b6b8e31c915 Mon Sep 17 00:00:00 2001 From: huyx Date: Wed, 10 Jul 2024 11:15:31 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=E5=91=8A=E8=AD=A6=E6=95=B4=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: huyx --- adapter/uhdf2/manager/src/devmgr_uevent.c | 8 ++++++++ adapter/uhdf2/shared/src/dev_attribute_serialize.c | 5 +++++ framework/support/posix/src/osal_mem.c | 8 ++++++++ 3 files changed, 21 insertions(+) diff --git a/adapter/uhdf2/manager/src/devmgr_uevent.c b/adapter/uhdf2/manager/src/devmgr_uevent.c index 87508b730..b6de031f0 100644 --- a/adapter/uhdf2/manager/src/devmgr_uevent.c +++ b/adapter/uhdf2/manager/src/devmgr_uevent.c @@ -173,6 +173,10 @@ static int32_t DevMgrUeventParseMatchKey(char *subStr, struct DListHead *matchKe HDF_LOGE("%{public}s OsalMemCalloc matchKey failed", __func__); return HDF_FAILURE; } + if (matchKey->value == NULL || matchKey->key == NULL) { + HDF_LOGE("%{public}s OsalMemCalloc matchKey->value or matchKey->key failed", __func__); + return HDF_FAILURE; + } DListHeadInit(&matchKey->entry); if (DevMgrUeventParseKeyValue(subStr, matchKey, KEY_VALUE_DELIMITER) == HDF_SUCCESS) { @@ -250,6 +254,10 @@ static int32_t DevMgrUeventParseRule(char *line) HDF_LOGE("%{public}s OsalMemCalloc ruleCfg failed", __func__); return HDF_FAILURE; } + if (ruleCfg->serviceName == NULL) { + HDF_LOGE("%{public}s OsalMemCalloc ruleCfg->serviceName failed", __func__); + return HDF_FAILURE; + } DListHeadInit(&ruleCfg->matchKeyList); char *ptr = line; diff --git a/adapter/uhdf2/shared/src/dev_attribute_serialize.c b/adapter/uhdf2/shared/src/dev_attribute_serialize.c index 31e1fc2e5..0f365ca9f 100644 --- a/adapter/uhdf2/shared/src/dev_attribute_serialize.c +++ b/adapter/uhdf2/shared/src/dev_attribute_serialize.c @@ -116,6 +116,11 @@ struct HdfDeviceInfo *DeviceAttributeDeserialize(struct HdfSBuf *sbuf) return NULL; } + if (attribute->deviceMatchAttr == NULL) { + HDF_LOGE("OsalMemCalloc failed, attribute->deviceMatchAttr is null"); + return NULL; + } + if (!HdfSbufReadUint32(sbuf, &attribute->deviceId) || !HdfSbufReadUint16(sbuf, &attribute->policy)) { HDF_LOGE("invalid deviceId or policy"); DeviceSerializedAttributeRelease(attribute); diff --git a/framework/support/posix/src/osal_mem.c b/framework/support/posix/src/osal_mem.c index e1c8b94a4..3dbf56471 100644 --- a/framework/support/posix/src/osal_mem.c +++ b/framework/support/posix/src/osal_mem.c @@ -21,6 +21,10 @@ void *OsalMemAlloc(size_t size) HDF_LOGE("%s invalid param", __func__); return NULL; } + if (size > SIZE_MAX) { + HDF_LOGE("%s invalid param : size", __func__); + return NULL; + } buf = malloc(size); @@ -35,6 +39,10 @@ void *OsalMemCalloc(size_t size) HDF_LOGE("%s invalid param", __func__); return NULL; } + if (size > SIZE_MAX) { + HDF_LOGE("%s invalid param : size", __func__); + return NULL; + } buf = OsalMemAlloc(size); if (buf != NULL) { -- Gitee From 827e1375f5249bb53df783d8898eb6af43c79d6e Mon Sep 17 00:00:00 2001 From: huyx Date: Thu, 11 Jul 2024 19:47:09 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=E5=91=8A=E8=AD=A6=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: huyx --- adapter/uhdf2/manager/src/devmgr_uevent.c | 6 ++---- adapter/uhdf2/shared/src/dev_attribute_serialize.c | 3 +-- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/adapter/uhdf2/manager/src/devmgr_uevent.c b/adapter/uhdf2/manager/src/devmgr_uevent.c index b6de031f0..52f630fb2 100644 --- a/adapter/uhdf2/manager/src/devmgr_uevent.c +++ b/adapter/uhdf2/manager/src/devmgr_uevent.c @@ -174,8 +174,7 @@ static int32_t DevMgrUeventParseMatchKey(char *subStr, struct DListHead *matchKe return HDF_FAILURE; } if (matchKey->value == NULL || matchKey->key == NULL) { - HDF_LOGE("%{public}s OsalMemCalloc matchKey->value or matchKey->key failed", __func__); - return HDF_FAILURE; + HDF_LOGW("%{public}s OsalMemCalloc matchKey->value or matchKey->key failed", __func__); } DListHeadInit(&matchKey->entry); @@ -255,8 +254,7 @@ static int32_t DevMgrUeventParseRule(char *line) return HDF_FAILURE; } if (ruleCfg->serviceName == NULL) { - HDF_LOGE("%{public}s OsalMemCalloc ruleCfg->serviceName failed", __func__); - return HDF_FAILURE; + HDF_LOGW("%{public}s OsalMemCalloc ruleCfg->serviceName failed", __func__); } DListHeadInit(&ruleCfg->matchKeyList); diff --git a/adapter/uhdf2/shared/src/dev_attribute_serialize.c b/adapter/uhdf2/shared/src/dev_attribute_serialize.c index 0f365ca9f..c7e91d0a4 100644 --- a/adapter/uhdf2/shared/src/dev_attribute_serialize.c +++ b/adapter/uhdf2/shared/src/dev_attribute_serialize.c @@ -117,8 +117,7 @@ struct HdfDeviceInfo *DeviceAttributeDeserialize(struct HdfSBuf *sbuf) } if (attribute->deviceMatchAttr == NULL) { - HDF_LOGE("OsalMemCalloc failed, attribute->deviceMatchAttr is null"); - return NULL; + HDF_LOGW("OsalMemCalloc failed, attribute->deviceMatchAttr is null"); } if (!HdfSbufReadUint32(sbuf, &attribute->deviceId) || !HdfSbufReadUint16(sbuf, &attribute->policy)) { -- Gitee From e0ba9156872cda3efa82373faab41645df05523c Mon Sep 17 00:00:00 2001 From: huyx Date: Fri, 12 Jul 2024 10:42:29 +0800 Subject: [PATCH 3/3] =?UTF-8?q?=E5=91=8A=E8=AD=A6=E6=95=B4=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: huyx --- adapter/uhdf2/host/src/devhost_service_stub.c | 4 ++-- framework/core/host/src/devhost_service.c | 22 +++++++++---------- framework/core/host/src/hdf_device.c | 4 ++-- framework/core/manager/src/devmgr_service.c | 2 +- 4 files changed, 16 insertions(+), 16 deletions(-) diff --git a/adapter/uhdf2/host/src/devhost_service_stub.c b/adapter/uhdf2/host/src/devhost_service_stub.c index 49804a4cb..2ed830204 100644 --- a/adapter/uhdf2/host/src/devhost_service_stub.c +++ b/adapter/uhdf2/host/src/devhost_service_stub.c @@ -41,7 +41,7 @@ static int DispatchAddDevice(struct IDevHostService *serviceIf, struct HdfSBuf * HDF_LOGE("Dispatch failed, attribute is null"); return HDF_FAILURE; } - HDF_LOGI("add device 0x%{public}x", attribute->deviceId); + HDF_LOGI("add device 0x%x", attribute->deviceId); int ret = serviceIf->AddDevice(serviceIf, attribute); if (ret != HDF_SUCCESS) { HDF_LOGE("Dispatch failed, add service failed and ret is %{public}d", ret); @@ -63,7 +63,7 @@ static int DispatchDelDevice(struct IDevHostService *serviceIf, struct HdfSBuf * return HDF_FAILURE; } - HDF_LOGI("del device 0x%{public}x", deviceId); + HDF_LOGI("del device 0x%x", deviceId); int ret = serviceIf->DelDevice(serviceIf, deviceId); if (ret != HDF_SUCCESS) { HDF_LOGE("del service failed, ret is %{public}d", ret); diff --git a/framework/core/host/src/devhost_service.c b/framework/core/host/src/devhost_service.c index 9ec409e5d..460af613f 100644 --- a/framework/core/host/src/devhost_service.c +++ b/framework/core/host/src/devhost_service.c @@ -47,7 +47,7 @@ static struct HdfDevice *DevHostServiceQueryOrAddDevice(struct DevHostService *i { struct HdfDevice *device = DevHostServiceFindDevice(inst, deviceId); if (device == NULL) { - HDF_LOGD("%{public}s can't find device %{public}d, try to create", __func__, deviceId); + HDF_LOGD("%{public}s can't find device %d, try to create", __func__, deviceId); device = HdfDeviceNewInstance(); if (device == NULL) { HDF_LOGE("Dev host service failed to create driver instance"); @@ -55,7 +55,7 @@ static struct HdfDevice *DevHostServiceQueryOrAddDevice(struct DevHostService *i } device->deviceId = MK_DEVID(inst->hostId, deviceId, 0); DListInsertHead(&device->node, &inst->devices); - HDF_LOGD("%{public}s add device %{public}d complete", __func__, deviceId); + HDF_LOGD("%{public}s add device %d complete", __func__, deviceId); } return device; } @@ -76,12 +76,12 @@ int DevHostServiceAddDevice(struct IDevHostService *inst, const struct HdfDevice device = DevHostServiceQueryOrAddDevice(hostService, DEVICEID(deviceInfo->deviceId)); if (device == NULL || device->super.Attach == NULL) { - HDF_LOGE("failed to add device %{public}d, device or Attach func is null", deviceInfo->deviceId); + HDF_LOGE("failed to add device %d, device or Attach func is null", deviceInfo->deviceId); return HDF_DEV_ERR_NO_DEVICE; } devNode = device->super.GetDeviceNode(&device->super, deviceInfo->deviceId); if (devNode != NULL) { - HDF_LOGE("failed to add device %{public}d, device already exist", deviceInfo->deviceId); + HDF_LOGE("failed to add device %d, device already exist", deviceInfo->deviceId); return HDF_ERR_DEVICE_BUSY; } driver = driverLoader->GetDriver(deviceInfo->moduleName); @@ -93,7 +93,7 @@ int DevHostServiceAddDevice(struct IDevHostService *inst, const struct HdfDevice devNode = HdfDeviceNodeNewInstance(deviceInfo, driver); if (devNode == NULL) { - HDF_LOGE("failed to add device %{public}d, create devNode failed", deviceInfo->deviceId); + HDF_LOGE("failed to add device %d, create devNode failed", deviceInfo->deviceId); driverLoader->ReclaimDriver(driver); return HDF_DEV_ERR_NO_MEMORY; } @@ -103,11 +103,11 @@ int DevHostServiceAddDevice(struct IDevHostService *inst, const struct HdfDevice devNode->driver = driver; ret = device->super.Attach(&device->super, devNode); if (ret != HDF_SUCCESS) { - HDF_LOGE("failed to add device %{public}d, attach devNode failed", deviceInfo->deviceId); + HDF_LOGE("failed to add device %d, attach devNode failed", deviceInfo->deviceId); HdfDeviceNodeFreeInstance(devNode); goto ERROR; } - HDF_LOGD("%{public}s add device %{public}d success", __func__, deviceInfo->deviceId); + HDF_LOGD("%{public}s add device %d success", __func__, deviceInfo->deviceId); return HDF_SUCCESS; ERROR: @@ -132,17 +132,17 @@ int DevHostServiceDelDevice(struct IDevHostService *inst, devid_t devId) devNode = device->super.GetDeviceNode(&device->super, devId); if (devNode == NULL) { - HDF_LOGI("failed to del device %{public}u, not exist", devId); + HDF_LOGI("failed to del device %u, not exist", devId); return HDF_DEV_ERR_NO_DEVICE; } if (device->super.Detach == NULL) { - HDF_LOGE("failed to del device %{public}u, invalid device", devId); + HDF_LOGE("failed to del device %u, invalid device", devId); return HDF_ERR_INVALID_OBJECT; } if (device->super.Detach(&device->super, devNode) != HDF_SUCCESS) { - HDF_LOGE("failed to detach device %{public}u", devId); + HDF_LOGE("failed to detach device %u", devId); return HDF_FAILURE; } HdfDeviceNodeFreeInstance(devNode); @@ -150,7 +150,7 @@ int DevHostServiceDelDevice(struct IDevHostService *inst, devid_t devId) if (DListIsEmpty(&device->devNodes)) { DevHostServiceFreeDevice(hostService, device); } - HDF_LOGD("%{public}s add device %{public}u success", __func__, devId); + HDF_LOGD("%{public}s add device %u success", __func__, devId); return HDF_SUCCESS; } diff --git a/framework/core/host/src/hdf_device.c b/framework/core/host/src/hdf_device.c index bf5cbe0a3..c6913f5ea 100644 --- a/framework/core/host/src/hdf_device.c +++ b/framework/core/host/src/hdf_device.c @@ -111,7 +111,7 @@ int HdfDeviceDetach(struct IHdfDevice *devInst, struct HdfDeviceNode *devNode) device = CONTAINER_OF(devInst, struct HdfDevice, super); if (DEVICEID(device->deviceId) != DEVICEID(devNode->devId)) { - HDF_LOGE("%{public}s: device %{public}x detach unknown devnode %{public}x", + HDF_LOGE("%{public}s: device %x detach unknown devnode %x", __func__, device->deviceId, devNode->devId); return HDF_DEV_ERR_NO_DEVICE; } @@ -143,7 +143,7 @@ static int HdfDeviceDetachWithDevid(struct IHdfDevice *device, devid_t devid) struct HdfDevice *dev = CONTAINER_OF(device, struct HdfDevice, super); struct HdfDeviceNode *devNode = HdfDeviceGetDeviceNode(device, devid); if (devNode == NULL) { - HDF_LOGE("detach device node %{public}x not in device %{public}x", devid, dev->deviceId); + HDF_LOGE("detach device node %x not in device %x", devid, dev->deviceId); return HDF_DEV_ERR_NO_DEVICE; } diff --git a/framework/core/manager/src/devmgr_service.c b/framework/core/manager/src/devmgr_service.c index 2e1cc1f7e..5e07f39cc 100644 --- a/framework/core/manager/src/devmgr_service.c +++ b/framework/core/manager/src/devmgr_service.c @@ -277,7 +277,7 @@ static int DevmgrServiceDetachDevice(struct IDevmgrService *inst, devid_t devid) } tokenClntNode = HdfSListSearch(&hostClnt->devices, devid, HdfSListHostSearchDeviceTokenComparer); if (tokenClntNode == NULL) { - HDF_LOGE("devmgr detach device %{public}x not found", devid); + HDF_LOGE("devmgr detach device %x not found", devid); return HDF_DEV_ERR_NO_DEVICE; } tokenClnt = CONTAINER_OF(tokenClntNode, struct DeviceTokenClnt, node); -- Gitee