From 8432be2dd7a7d006605f33d26954aa6d53120536 Mon Sep 17 00:00:00 2001 From: Heewon Park Date: Thu, 21 May 2015 16:25:22 +0900 Subject: [PATCH] Fix for the prevent issues for Notification Manager. Referenece CID: 65774, 65791, 65825, 65829, 65830, 65831, 65833 65840, 65841, 65844, 65846, 65852, 65854, 65866 Change-Id: I85cc23d58317fced911314ba8684dec7bacf42e5 Signed-off-by: Heewon Park Reviewed-on: https://gerrit.iotivity.org/gerrit/1060 Tested-by: jenkins-iotivity Reviewed-by: Uze Choi --- .../NotificationManager/src/hosting.c | 35 +++++++++++-------- .../NotificationManager/src/virtualResource.c | 27 +++++++------- 2 files changed, 33 insertions(+), 29 deletions(-) diff --git a/service/notification-manager/NotificationManager/src/hosting.c b/service/notification-manager/NotificationManager/src/hosting.c index 0c2391d23..dc74925f4 100644 --- a/service/notification-manager/NotificationManager/src/hosting.c +++ b/service/notification-manager/NotificationManager/src/hosting.c @@ -328,21 +328,24 @@ OCStackResult registerResourceAsCoordinatable(OCResourceHandle *handle, OCEntityHandler entityHandler, uint8_t resourceProperties) { - - char *coordinatingURI = (char *)malloc(sizeof(char) * - (strlen(resourceUri) + strlen(OIC_COORDINATING_FLAG))); + OCStackResult ret = OC_STACK_OK; + size_t coordinateUriLen = sizeof(char) * (strlen(resourceUri) + + strlen(OIC_COORDINATING_FLAG) + 1); + char *coordinatingURI = (char *)malloc(coordinateUriLen); if(coordinatingURI == NULL) { OC_LOG_V(DEBUG, HOSTING_TAG, "memory alloc fail : coordinatingURI"); return OC_STACK_NO_MEMORY; } - snprintf(coordinatingURI, sizeof(coordinatingURI), "%s%s", resourceUri, OIC_COORDINATING_FLAG); + snprintf(coordinatingURI, coordinateUriLen,"%s%s", resourceUri, OIC_COORDINATING_FLAG); OC_LOG_V(DEBUG, HOSTING_TAG, "requiredUri+coordinatingFlag = %s", coordinatingURI); - return OCCreateResource(handle, resourceTypeName, resourceInterfaceName, + ret = OCCreateResource(handle, resourceTypeName, resourceInterfaceName, coordinatingURI, entityHandler, resourceProperties); + free(coordinatingURI); + return ret; } /* @@ -514,6 +517,7 @@ OCStackApplicationResult requestCoordinateeCandidateDiscoveryCB(void *ctx, OCDoH if (vList->headerNode == NULL) { OC_LOG(DEBUG, HOSTING_TAG, "This Discover Response is empty"); + destroyMirrorResourceList(vList); return ret; } @@ -640,12 +644,10 @@ MirrorResourceList *buildMirrorResourceList(OCDoHandle handle, OCClientResponse MirrorResource *buildMirrorResource(cJSON *ocArray_sub) { - MirrorResource *mirrorResource = NULL; - char temp[OIC_STRING_MAX_VALUE] = {'\0'}; - strncpy(temp, cJSON_GetObjectItem(ocArray_sub, "href")->valuestring, sizeof(temp)); + const char *curValuestring = cJSON_GetObjectItem(ocArray_sub, "href")->valuestring; - if ( strstr(temp, OIC_COORDINATING_FLAG) ) + if ( strstr(curValuestring, OIC_COORDINATING_FLAG) ) { mirrorResource = createMirrorResource(); if(mirrorResource == NULL) @@ -660,8 +662,8 @@ MirrorResource *buildMirrorResource(cJSON *ocArray_sub) OC_LOG_V(DEBUG, HOSTING_TAG, "memory alloc fail for mirrorResource uri"); goto RET_ERROR; } - strncpy(mirrorResource->uri, temp, strlen(temp) - strlen(OIC_COORDINATING_FLAG)); - mirrorResource->uri[strlen(temp) - strlen(OIC_COORDINATING_FLAG)] = '\0'; + strncpy(mirrorResource->uri, curValuestring, strlen(curValuestring) - strlen(OIC_COORDINATING_FLAG)); + mirrorResource->uri[strlen(curValuestring) - strlen(OIC_COORDINATING_FLAG)] = '\0'; OC_LOG_V(DEBUG, HOSTING_TAG, "VirtualResource URI : %s", mirrorResource->uri); cJSON *inArray_sub = cJSON_GetObjectItem(ocArray_sub, "prop"); @@ -966,7 +968,7 @@ MirrorResource *updateMirrorResource(OCDoHandle handle, const char *payload) cJSON *json = cJSON_CreateObject(); char nodeData[OIC_STRING_MAX_VALUE] = {'\0'}; - snprintf(nodeData, sizeof(foundMirrorResource->uri), "%s", foundMirrorResource->uri); + snprintf(nodeData, sizeof(nodeData), "%s", foundMirrorResource->uri); cJSON_AddStringToObject(json, "href", nodeData); cJSON *nodeRep = cJSON_Parse(cJSON_PrintUnformatted(foundMirrorResource->rep)); @@ -1249,7 +1251,9 @@ OCStackResult requestIsAlive(const char *address) if (result != OC_STACK_OK) { OC_LOG_V(DEBUG, HOSTING_TAG, "Insert request list : fail3"); - return result; + destroyRequestHandle(requestAlive); + mirrorResource = mirrorResource->next; + continue; } result = requestQuery(requestAlive, OC_REST_GET, address, mirrorResource->uri); @@ -1463,6 +1467,7 @@ OCEntityHandlerResponse buildEntityHandlerResponse(OCEntityHandlerRequest *entit { OC_LOG_V(DEBUG, HOSTING_TAG, "enter buildEntityHandlerResponse"); OCEntityHandlerResponse response; + memset(&response, 0, sizeof(response)); OCEntityHandlerResult entityHandlerResult = OC_EH_OK; char payload[MAX_RESPONSE_LENGTH] = {'\0'}; @@ -1517,7 +1522,7 @@ OCEntityHandlerResult handleRequestPayload (OCEntityHandlerRequest *entityHandle if (entityHandlerRequest->method == OC_REST_DELETE) { - memset(payload, '\0', sizeof(payload)); + memset(payload, '\0', sizeof(char) * (maxPayloadSize + 1)); OC_LOG_V(DEBUG, HOSTING_TAG, "DELETE"); return OC_EH_RESOURCE_DELETED; } @@ -1530,7 +1535,7 @@ OCEntityHandlerResult handleRequestPayload (OCEntityHandlerRequest *entityHandle if (maxPayloadSize > strlen ((char *)responsePayload)) { - strncpy(payload, responsePayload, sizeof(payload)); + strncpy(payload, responsePayload, strlen ((char *)responsePayload)); entityHandlerResult = OC_EH_OK; } else diff --git a/service/notification-manager/NotificationManager/src/virtualResource.c b/service/notification-manager/NotificationManager/src/virtualResource.c index 2f33ad0b6..9dae0b298 100644 --- a/service/notification-manager/NotificationManager/src/virtualResource.c +++ b/service/notification-manager/NotificationManager/src/virtualResource.c @@ -166,14 +166,14 @@ OCStackResult insertMirrorResource(MirrorResourceList *mirrorResourceList, MirrorResource *findMirrorResourceUsingAddressAndURI(MirrorResourceList *mirrorResourceList, const char *address, OICResourceCoordinatorParamType paramType, const char *uri) { - if (mirrorResourceList->headerNode == NULL) + if (mirrorResourceList == NULL || address == NULL) { - OC_LOG_V(DEBUG, VR_TAG,"Find Virtual Resource : Empty Virtual Resource List."); + OC_LOG_V(DEBUG, VR_TAG,"Find Virtual Resource : invalid parameter."); return NULL; } - if (mirrorResourceList == NULL || address == NULL) + if (mirrorResourceList->headerNode == NULL) { - OC_LOG_V(DEBUG, VR_TAG,"Find Virtual Resource : invalid parameter."); + OC_LOG_V(DEBUG, VR_TAG,"Find Virtual Resource : Empty Virtual Resource List."); return NULL; } @@ -281,6 +281,7 @@ OCStackResult ejectMirrorResource(MirrorResourceList *mirrorResourceList, if (mirrorResourceList->headerNode == NULL) { OC_LOG_V(DEBUG, VR_TAG, "Eject Virtual Resource : Empty Virtual Resource List."); + return OC_STACK_ERROR; } if (mirrorResource == mirrorResourceList->headerNode) @@ -340,22 +341,12 @@ MirrorResource *cloneMirrorResource(MirrorResource *sourceMirrorResource) strcpy(clonedMirrorResource->address[i], sourceMirrorResource->address[i]); } - // copy prop ?? - return clonedMirrorResource; } MirrorResourceList *findMirrorResourceListUsingAddress(MirrorResourceList *mirrorResourceList, const char *address, OICResourceCoordinatorParamType paramType) { - - MirrorResource *tempNode = mirrorResourceList->headerNode; - while (tempNode != NULL) - { - OC_LOG_V(DEBUG, VR_TAG, "uri = %s", tempNode->uri); - tempNode = tempNode->next; - } - if (mirrorResourceList == NULL || address == NULL) { OC_LOG_V(DEBUG, VR_TAG,"Find Virtual Resource List : invalid parameter."); @@ -367,6 +358,14 @@ MirrorResourceList *findMirrorResourceListUsingAddress(MirrorResourceList *mirro return NULL; } + MirrorResource *tempNode = mirrorResourceList->headerNode; + while (tempNode != NULL) + { + OC_LOG_V(DEBUG, VR_TAG, "uri = %s", tempNode->uri); + tempNode = tempNode->next; + } + + MirrorResourceList *resultMirrorResourceList = createMirrorResourceList(); MirrorResource *mirrorResource = mirrorResourceList->headerNode; while (mirrorResource != NULL) -- 2.34.1