From daa3461e745e26015cb5c158d00ddbcb9385b3a4 Mon Sep 17 00:00:00 2001 From: Charlie Lenahan Date: Mon, 20 Apr 2015 19:30:35 -0400 Subject: [PATCH] Fix crash in csdk/sample/ocserver on resource PUT. If a client does a resource PUT with only power OR state (not both), then it will crash. Change-Id: If19ce5edaf1f3538443074e8a66fa836ef5290c9 Signed-off-by: Charlie Lenahan Reviewed-on: https://gerrit.iotivity.org/gerrit/788 Tested-by: jenkins-iotivity Reviewed-by: Erich Keane --- .../stack/samples/linux/SimpleClientServer/ocserver.cpp | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/resource/csdk/stack/samples/linux/SimpleClientServer/ocserver.cpp b/resource/csdk/stack/samples/linux/SimpleClientServer/ocserver.cpp index 88668e9..3b8260e 100644 --- a/resource/csdk/stack/samples/linux/SimpleClientServer/ocserver.cpp +++ b/resource/csdk/stack/samples/linux/SimpleClientServer/ocserver.cpp @@ -112,8 +112,17 @@ char* constructJsonResponse (OCEntityHandlerRequest *ehRequest) carrier = cJSON_GetArrayItem(carrier, 0); carrier = cJSON_GetObjectItem(carrier, "rep"); - currLightResource->power = cJSON_GetObjectItem(carrier,"power")->valueint; - currLightResource->state = cJSON_GetObjectItem(carrier,"state")->valueint; + cJSON* prop = cJSON_GetObjectItem(carrier,"power"); + if (prop) + { + currLightResource->power =prop->valueint; + } + + prop = cJSON_GetObjectItem(carrier,"state"); + if (prop) + { + currLightResource->state = prop->valueint; + } cJSON_Delete(putJson); } -- 2.7.4