From d9121babfc07a9ecc54dd46ef02d6f6b0e8775a3 Mon Sep 17 00:00:00 2001 From: Ravi Nanjundappa Date: Tue, 22 Sep 2015 10:08:19 +0530 Subject: [PATCH] resource: Fix cppcheck issues in resource/csdk/security/ dir This patch fixes the "(error) Possible null pointer dereference:" issues reported by cppcheck tool in resource/csdk/security/ directory. Change-Id: I36c41312fe3d78edd43c6c505b875ecbb6ba0dfa Signed-off-by: Ravi Nanjundappa Reviewed-on: https://gerrit.iotivity.org/gerrit/2905 Tested-by: jenkins-iotivity Reviewed-by: Jon A. Cruz Reviewed-by: Shilpa Sodani Reviewed-by: Madan Lanka --- resource/csdk/security/src/amsmgr.c | 3 ++- resource/csdk/security/src/policyengine.c | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/resource/csdk/security/src/amsmgr.c b/resource/csdk/security/src/amsmgr.c index 365cb10..c0f7377 100644 --- a/resource/csdk/security/src/amsmgr.c +++ b/resource/csdk/security/src/amsmgr.c @@ -199,7 +199,8 @@ static OCStackApplicationResult SecurePortDiscoveryCallback(void *ctx, OCDoHandl OCResourcePayload* resPayload = ((OCDiscoveryPayload*)clientResponse->payload)->resources; //Verifying if the ID of the sender is an AMS service that this device trusts. - if(memcmp(context->amsMgrContext->amsDeviceId.id, resPayload->sid, + if(resPayload && + memcmp(context->amsMgrContext->amsDeviceId.id, resPayload->sid, sizeof(context->amsMgrContext->amsDeviceId.id)) != 0) { context->retVal = ACCESS_DENIED_AMS_SERVICE_ERROR; diff --git a/resource/csdk/security/src/policyengine.c b/resource/csdk/security/src/policyengine.c index 3515c07..196a778 100644 --- a/resource/csdk/security/src/policyengine.c +++ b/resource/csdk/security/src/policyengine.c @@ -429,9 +429,9 @@ exit: */ OCStackResult InitPolicyEngine(PEContext_t *context) { - context->amsMgrContext = (AmsMgrContext_t *)OICMalloc(sizeof(AmsMgrContext_t)); if(NULL != context) { + context->amsMgrContext = (AmsMgrContext_t *)OICMalloc(sizeof(AmsMgrContext_t)); SetPolicyEngineState(context, AWAITING_REQUEST); } @@ -449,7 +449,7 @@ void DeInitPolicyEngine(PEContext_t *context) if(NULL != context) { SetPolicyEngineState(context, STOPPED); + OICFree(context->amsMgrContext); } - OICFree(context->amsMgrContext); return; } -- 2.7.4