From 2950122adf57c0473fc372d2084d41af1acf91d4 Mon Sep 17 00:00:00 2001 From: "jaesick.shin" Date: Wed, 14 Dec 2016 17:30:55 +0900 Subject: [PATCH] bug fix about related memory and security resource. 1. I did not copy the memory, but I freed the memory while I was using it. 2. The initial value of the securityResource variable used by the provider was wrong. second patch include, 1. change OICCalloc to OICMalloc. 2. removed the initialization code from the previous commit, so added it again. Change-Id: I189eb720785a74e39955640484e795170be3b010 Signed-off-by: jaesick.shin Reviewed-on: https://gerrit.iotivity.org/gerrit/15593 Tested-by: jenkins-iotivity Reviewed-by: Uze Choi --- service/notification/src/common/NSUtil.c | 11 +++++------ service/notification/src/provider/NSProviderSubscription.c | 4 +++- service/notification/src/provider/NSProviderSystem.c | 2 +- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/service/notification/src/common/NSUtil.c b/service/notification/src/common/NSUtil.c index 9bcf11e..0aeb489 100755 --- a/service/notification/src/common/NSUtil.c +++ b/service/notification/src/common/NSUtil.c @@ -29,10 +29,13 @@ OCEntityHandlerRequest *NSCopyOCEntityHandlerRequest(OCEntityHandlerRequest *ent if (copyOfRequest) { - // Do shallow copy memcpy(copyOfRequest, entityHandlerRequest, sizeof(OCEntityHandlerRequest)); + copyOfRequest->payload = NULL; + copyOfRequest->query = NULL; + copyOfRequest->numRcvdVendorSpecificHeaderOptions = 0; + copyOfRequest->rcvdVendorSpecificHeaderOptions = NULL; - if (copyOfRequest->query) + if (entityHandlerRequest->query) { copyOfRequest->query = OICStrdup(entityHandlerRequest->query); if (!copyOfRequest->query) @@ -48,10 +51,6 @@ OCEntityHandlerRequest *NSCopyOCEntityHandlerRequest(OCEntityHandlerRequest *ent copyOfRequest->payload = (OCPayload *) (OCRepPayloadClone ((OCRepPayload*) entityHandlerRequest->payload)); } - - // Ignore vendor specific header options for example - copyOfRequest->numRcvdVendorSpecificHeaderOptions = 0; - copyOfRequest->rcvdVendorSpecificHeaderOptions = NULL; } if (copyOfRequest) diff --git a/service/notification/src/provider/NSProviderSubscription.c b/service/notification/src/provider/NSProviderSubscription.c index d2563ce..12ef5d1 100644 --- a/service/notification/src/provider/NSProviderSubscription.c +++ b/service/notification/src/provider/NSProviderSubscription.c @@ -183,7 +183,7 @@ void NSHandleSubscription(OCEntityHandlerRequest *entityHandlerRequest, NSResour } bool currPolicy = NSGetPolicy(); - NSAskAcceptanceToUser(entityHandlerRequest); + NSAskAcceptanceToUser(NSCopyOCEntityHandlerRequest(entityHandlerRequest)); if (currPolicy == NS_POLICY_PROVIDER) { @@ -194,6 +194,8 @@ void NSHandleSubscription(OCEntityHandlerRequest *entityHandlerRequest, NSResour NS_LOG(DEBUG, "NSGetSubscriptionAccepter == NS_ACCEPTER_CONSUMER"); NSSendConsumerSubResponse(NSCopyOCEntityHandlerRequest(entityHandlerRequest)); } + + NSFreeOCEntityHandlerRequest(entityHandlerRequest); } else if (resourceType == NS_RESOURCE_SYNC) { diff --git a/service/notification/src/provider/NSProviderSystem.c b/service/notification/src/provider/NSProviderSystem.c index 089a5b7..8ebf078 100644 --- a/service/notification/src/provider/NSProviderSystem.c +++ b/service/notification/src/provider/NSProviderSystem.c @@ -32,7 +32,7 @@ static NSConnectionState NSProviderConnectionState; NSProviderInfo * providerInfo; bool NSPolicy = true; -bool NSResourceSecurity = true; +bool NSResourceSecurity = false; void NSSetProviderConnectionState(NSConnectionState state) { -- 2.7.4