Fix possible NULL pointer dereference
authorGeorge Nash <george.nash@intel.com>
Fri, 9 Dec 2016 17:55:59 +0000 (09:55 -0800)
committerUze Choi <uzchoi@samsung.com>
Thu, 22 Dec 2016 07:19:10 +0000 (07:19 +0000)
if *userdata was a NULL pointer it would be dereferenced
it even after a NULL pointer check. The dereference
was moved inside the NULL pointer check to prevent the
pointer dereference.

Change-Id: I334d56c210e81329bcfef9936fbe653cc5561e8f
Signed-off-by: George Nash <george.nash@intel.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/15371
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: Jihun Ha <jihun.ha@samsung.com>
Reviewed-by: JungYong KIM <jyong2.kim@samsung.com>
Reviewed-by: Habib Virji <habib.virji@samsung.com>
Reviewed-by: Uze Choi <uzchoi@samsung.com>
service/easy-setup/sampleapp/enrollee/linux/easysetup_x.c

index aaa351b..5a1f29a 100755 (executable)
@@ -56,10 +56,10 @@ void ReadUserdataCb(OCRepPayload* payload, char* resourceType, void** userdata)
                 if(*userdata != NULL)
                 {
                     *userdata = (void*)OICMalloc(sizeof(UserProperties));
+                    ((UserProperties*)(*userdata))->userValue_int = value;
                 }
                 OIC_LOG_V(INFO, ESX_ENROLLEE_TAG, "[User specific property] %s : %ld",
                                                                             USERPROPERTY_KEY_INT, value);
-                ((UserProperties*)(*userdata))->userValue_int = value;
                 g_userProperties.userValue_int = value;
             }
         }