[Internal:Prevent] Fixed for prevent defect. (13EA)
authorsanghyuk Ko <sanghyuk.ko@samsung.com>
Mon, 15 Jul 2013 05:10:53 +0000 (14:10 +0900)
committersanghyuk Ko <sanghyuk.ko@samsung.com>
Mon, 15 Jul 2013 05:10:53 +0000 (14:10 +0900)
[Problem]
-
[Cause]
-
[Solution]
- Fixed for prevent defect. (13EA - CID 64220, 64219, 64218, 53768, 53767, 53766, 53765, 53764, 53763, 53762, 53761, 53759, 26658)

Change-Id: I67822673879398e0d130d10f7f1a082b9fcfabaf

src/agent/dm-engine/cp/dm_cp_processor.c
src/agent/serviceadapter/dm-phase-handler/dm_phase_handler.c
src/agent/serviceadapter/sa_session.c
src/agent/serviceadapter/sa_util.c
src/plugins/dm-private/slp-device-dm/src/plugin_slp_device_ctrl.c

index ce1ffe5..489e348 100755 (executable)
@@ -699,6 +699,8 @@ static CP_ERROR _process_receieved_cp_stream(CP_TYPE cp_type, const char *msgBod
        if (dm_cp_data->dm_cp == 0) {
                _DEBUG_TRACE("parsing_cp_stream() failed !!");
                /* todo : exception handling */
+               free(dm_cp_data); // prevent
+               dm_cp_data = NULL; // prevent
                _INNER_FUNC_EXIT;
                return CP_ERROR_FAIL;
        }
@@ -725,6 +727,10 @@ static CP_ERROR _process_receieved_cp_stream(CP_TYPE cp_type, const char *msgBod
 
        if (msgData == NULL) {
                _DEBUG_TRACE("calloc failed !!");
+               if(send_msg != NULL) { // prevent
+                       free(send_msg);
+                       send_msg = NULL;
+               }
                _INNER_FUNC_EXIT;
                return CP_ERROR_FAIL;
        }
@@ -736,6 +742,11 @@ static CP_ERROR _process_receieved_cp_stream(CP_TYPE cp_type, const char *msgBod
                if (msgData != NULL)
                        free(msgData);
 
+               if(send_msg != NULL) { // prevent
+                       free(send_msg);
+                       send_msg = NULL;
+               }
+       
                _INNER_FUNC_EXIT;
                return CP_ERROR_FAIL;
        } else {
@@ -1095,6 +1106,7 @@ static CP_ERROR _process_setting_oma_dm(DM_CP * dm_cp)
 
  error:
        _DEBUG_TRACE("error : %d", ret);
+       free_dm_acc(dmaccount); // prevent
        _INNER_FUNC_EXIT;
        return ret;
 
index 67e781e..20c0dba 100755 (executable)
@@ -162,6 +162,8 @@ static DM_ERROR _generate_setupphase_msg(Session ** session, char *pServer_id, c
        char *targetUrl = NULL;
        int isBase64 = 0;
        char *nextNonce = NULL;
+       SyncML *pSyncML = NULL;
+       Command *pReplaceCommand = NULL;
 
        ret = __get_dmaccInfo(pServer_id, &client_id, &client_pwd, &sourceUrl, &targetUrl, &isBase64, &nextNonce);
        if (ret != DM_OK)
@@ -234,7 +236,7 @@ static DM_ERROR _generate_setupphase_msg(Session ** session, char *pServer_id, c
        putCmdIntoList(&commands, &commands_last, pAlertCommand);
 
        /* create replace */
-       Command *pReplaceCommand = NULL;
+       //Command *pReplaceCommand = NULL;
        ret = __create_devinfo_replace_cmd((*session), &pReplaceCommand);
        if (ret != DM_OK)
                goto error;
@@ -299,7 +301,7 @@ static DM_ERROR _generate_setupphase_msg(Session ** session, char *pServer_id, c
 
 
        /*create SyncML */
-       SyncML *pSyncML = NULL;
+       //SyncML *pSyncML = NULL;
        ret = create_syncml(pSyncHdr, NULL, commands, isFinal, &pSyncML);
        if (ret != DM_OK)
                goto error;
@@ -339,6 +341,7 @@ static DM_ERROR _generate_setupphase_msg(Session ** session, char *pServer_id, c
        str_free(&contenttype);
        str_free(&data);
 
+       str_free(&nextNonce); // prevent
 
        _INNER_FUNC_EXIT;
        return ret;
@@ -353,6 +356,11 @@ static DM_ERROR _generate_setupphase_msg(Session ** session, char *pServer_id, c
        str_free(&contenttype);
        str_free(&data);
 
+       if(pSyncML != NULL) { // prevent
+               free_syncml(pSyncML);
+               pSyncML = NULL;
+       }
+       str_free(&nextNonce); // prevent
 
        _INNER_FUNC_EXIT;
        return ret;
@@ -867,6 +875,7 @@ static DM_ERROR _generate_generic_alert(Session ** session, char *pServer_id, ch
        char *data = NULL;
        char *pCorrelator = NULL;
        char *rSourceUrl = NULL;
+       SyncML *pSyncML = NULL;
 
        /*Client init */
 
@@ -1004,7 +1013,7 @@ static DM_ERROR _generate_generic_alert(Session ** session, char *pServer_id, ch
        putCmdIntoList(&commands, &commands_last, pReplaceCommand);
 
        /*create SyncML */
-       SyncML *pSyncML = NULL;
+       //SyncML *pSyncML = NULL;
        ret = create_syncml(pSyncHdr, NULL, commands, isFinal, &pSyncML);
        if (ret != DM_OK)
                goto error;
@@ -1049,6 +1058,8 @@ static DM_ERROR _generate_generic_alert(Session ** session, char *pServer_id, ch
        str_free(&rSourceUrl);
        str_free(&data);
 
+       str_free(&nextNonce); // prevent
+       str_free(&contenttype); // prevent
        _INNER_FUNC_EXIT;
        return ret;
 
@@ -1061,6 +1072,17 @@ static DM_ERROR _generate_generic_alert(Session ** session, char *pServer_id, ch
        str_free((&data));
 
        _DEBUG_TRACE(" error : %d\n", ret);
+       str_free(&nextNonce); // prevent
+       str_free(&contenttype); // prevent
+
+       if(pSyncML != NULL) { // prevent
+               free_syncml(pSyncML);
+               pSyncML = NULL;
+       }
+       free_command(pReplaceCommand); // prevent
+       free_command(pAlertCommand); // prevent
+       free_synchdr(pSyncHdr); // prevent
+
        _INNER_FUNC_EXIT;
        return ret;
 }
index 9865c53..eb04ebf 100755 (executable)
@@ -750,7 +750,7 @@ static DM_ERROR _receive_changes_cmd(Session * session, Command * command)
                                                                goto error;
                                                        } else { // Permanent node. But device need execution about replace cmd.
                                                                char *server_id = NULL;
-                                                               targetUrl = get_location_locuri(item->target);
+                                                               //targetUrl = get_location_locuri(item->target);
                                                                server_id = session->pServer_id;
                                                                _DEBUG_TRACE("server_id [%s]", server_id);
                                                                //ret = engine_replace_start(server_id, targetUrl, &(session->service_engine_id), &resultStatus, item);
index 51c6bb6..fdb0c94 100755 (executable)
@@ -225,6 +225,12 @@ DM_ERROR gemerate_hmac(char *username, char *password, unsigned char *nonce, uns
        if (str_len >= sizeof(buffer)) {
                _DEBUG_INFO("buffer over flow");
                ret = COMMON_ERR_BUFFER_OVERFLOW;
+
+               if(digest_msg != NULL) {
+                       free(digest_msg);
+                       digest_msg = NULL;
+               }
+
                _EXTERN_FUNC_EXIT;
                return ret;
        }
@@ -245,6 +251,12 @@ DM_ERROR gemerate_hmac(char *username, char *password, unsigned char *nonce, uns
        if (str_len >= sizeof(buffer)) {
                _DEBUG_INFO("buffer over flow");
                ret = COMMON_ERR_BUFFER_OVERFLOW;
+
+               if(digest_msg != NULL) {
+                       free(digest_msg);
+                       digest_msg = NULL;
+               }
+
                _EXTERN_FUNC_EXIT;
                return ret;
        }
@@ -306,6 +318,10 @@ DM_ERROR gemerate_hmac(char *username, char *password, unsigned char *nonce, uns
        (*mac) = strdup((const char *)temp_result3);
        str_free((char **)(&temp_result3));
 
+       if(digest_msg != NULL) {
+               free(digest_msg);
+               digest_msg = NULL;
+       }
        _EXTERN_FUNC_EXIT;
        return ret;
 
index 7a36815..a0f6384 100755 (executable)
@@ -39,7 +39,7 @@
 #define UA_RESULT_KEY "db/SyncML/oma-dm-service/UAresult"
 
 //#define RB_ERR_CODE_MAX_COUNT 16
-#define RB_ERR_CODE_MAX_COUNT 7
+#define RB_ERR_CODE_MAX_COUNT 20
 
 typedef struct _type_Redbend_OMADM_Table {
        int result_code;
@@ -49,31 +49,26 @@ typedef struct _type_Redbend_OMADM_Table {
 } type_redbend_omadm_table_s;
 
 type_redbend_omadm_table_s redbend_omadm_table[RB_ERR_CODE_MAX_COUNT] = {
-/*
-       {200, "Successful", "0", "S_RB_SUCCESS"},
-       {410, "Firmware Update Failed", "1", "E_RB_*"}, // juhaki.park
-       {402, "Corrupted Firmware Update Package", "8000000D", "E_RB_PKG_CORRUPTED"},
-       {403, "Firmware Update Package - Device Mismatch", "80000002", "E_RB_BAD_PARAMS"},
-       {403, "Firmware Update Package - Device Mismatch", "80000011", "E_RB_WRONG_UPI_VER"},
-       {403, "Firmware Update Package - Device Mismatch", "80000012", "E_RB_WRONG_UPI_UPDATE"},
-       {403, "Firmware Update Package - Device Mismatch", "80000013", "E_RB_UPDATE_SECTOR_SIG"},
-       {404, "Failed Firmware Update Package Validation", "8001001A", "E_RB_NON_DP_FORMAT_NOT_SUPPORTED"},
-       {404, "Failed Firmware Update Package Validation", "80010025", "E_RB_INVALID_DP_HEADER"},
-       {404, "Failed Firmware Update Package Validation", "80010026", "E_RB_INVALID_DP_WRONG_SIGNATURE"},
-       {404, "Failed Firmware Update Package Validation", "80010027", "E_RB_INVALID_DP"},
-       {405, "Firmware Update Package Not Acceptable", "8000000B", "E_RB_PKG_TOO_SHORT"},
-       {405, "Firmware Update Package Not Acceptable", "8000000C", "E_RB_PKG_TOO_LONG"},
-       {405, "Firmware Update Package Not Acceptable", "8000000E", "E_RB_PKG_NOT_AUTHORIZED"},
-       {410, "Firmware Update Failed", "**", "E_RB_*"},
-       {502, "Firmware update fails due to device out of memory", "8000001E", "E_RB_NOT_ENOUGH_RAM"},
-*/
-       {200, "Successful", "0", "S_RB_SUCCESS"},
-       {410, "Firmware Update Failed", "FDBC", "E_RB_Bootloader_update_error"},        // juhaki.park
-       {410, "Firmware Update Failed", "fdbc", "E_RB_Bootloader_update_error"},        // juhaki.park
-       {410, "Firmware Update Failed", "FDBD", "E_RB_Boot_partition_update_error"},    // juhaki.park
-       {410, "Firmware Update Failed", "fdbd", "E_RB_Boot_partition_update_error"},    // juhaki.park
-       {410, "Firmware Update Failed", "FDBE", "E_RB_Platform_update_error"},  // juhaki.park
-       {410, "Firmware Update Failed", "fdbe", "E_RB_Platform_update_error"},  // juhaki.park
+       {200, "Successful",                                                                             "0", NULL},
+       {410, "UPI_DELTA_PATH_ERROR",                                           "fdaa", NULL},
+       {410, "UPI_DELTA_PATH_LENGTH_ERROR",                            "fdab", NULL},
+       {410, "UPI_GUI_INIT_ERROR",                                                     "fdba", NULL},
+       {410, "UPI_VERSION_ERROR",                                                      "fdbb", NULL},
+       {410, "UPI_SBL_VERIFY_ERROR",                                           "fdca", NULL},
+       {410, "UPI_BOOT_VERIFY_ERROR",                                          "fdcb", "kernel verification fail"},
+       {410, "UPI_PLATFORM_VERIFY_ERROR",                                      "fdcc", "platform verification fail"},
+       {410, "UPI_CSC_VERIFY_ERROR",                                           "fdcd", "csc verification fail"},
+       {410, "UPI_MODEM_VERIFY_ERROR",                                                 "fdce", "modem verification fail"},
+       {410, "UPI_SBL_UPDATE_ERROR",                                           "fdda", "bootloader update fail"},
+       {410, "UPI_BOOT_UPDATE_ERROR",                                          "fddb", "kernel update fail"},
+       {410, "UPI_PLATFORM_UPDATE_ERROR",                                      "fddc", "platform update fail"},
+       {410, "UPI_CSC_UPDATE_ERROR",                                           "fddd", "csc update fail"},
+       {410, "UPI_MODEM_UPDATE_ERROR",                                                 "fdde", "modem update fail"},
+       {410, "UPI_INVALID_PARAM_ERROR",                                        "fdea", NULL},
+       {410, "UPI_STATUSFLAG_ERROR",                                           "fdeb", NULL},
+       {410, "UPI_DELTACOUNT_ERROR",                                           "fdec", "no delta file"},
+       {410, "UPI_NO_DELTA_ERROR",                                                     "fdfa", NULL},
+       {410, "UPI_NO_UA_ERROR",                                                                "fdfb", NULL},
 
 /*{0, NULL, NULL, NULL},*/
 };
@@ -133,7 +128,7 @@ error:
 */
 }
 
-void slp_device_ctrl_get_fota_fail_ua_result(char * str_UA_file_position)
+char* slp_device_ctrl_get_fota_fail_ua_result()
 {
        _EXTERN_FUNC_ENTER;
        FILE *file_des;
@@ -145,7 +140,7 @@ void slp_device_ctrl_get_fota_fail_ua_result(char * str_UA_file_position)
        if (file_des == NULL) {
                _DEBUG_INFO("fopen fail - cause file \n");
                _EXTERN_FUNC_EXIT;
-               return;
+               return NULL;
        }
        fseek(file_des, 0, SEEK_END);
        lSize = ftell(file_des);
@@ -154,7 +149,7 @@ void slp_device_ctrl_get_fota_fail_ua_result(char * str_UA_file_position)
                if (file_des != NULL)
                        fclose(file_des);
                _EXTERN_FUNC_EXIT;
-               return;
+               return NULL;
        }
        rewind(file_des);
        char *str_result = NULL;
@@ -165,7 +160,7 @@ void slp_device_ctrl_get_fota_fail_ua_result(char * str_UA_file_position)
                        fclose(file_des);
                _DEBUG_INFO("malloc fail \n");
                _EXTERN_FUNC_EXIT;
-               return;
+               return NULL;
        }
        memset(str_result, 0x0, sizeof(char)*(lSize+1));        // PREVENT
 
@@ -179,36 +174,18 @@ void slp_device_ctrl_get_fota_fail_ua_result(char * str_UA_file_position)
                        free(str_result);
 
                _EXTERN_FUNC_EXIT;
-               return;
+               return NULL;
        }
        if (str_result[lSize - 1] == '\n')
                str_result[lSize - 1] = 0;
 
-       if(lSize > 0) {
-               int vconf_result = 0;
-               char str_ua_result[128] = {0,};
-               if(str_UA_file_position == NULL) {
-                       snprintf(str_ua_result,128,"NoData-%s", str_result);
-               } else {
-                       snprintf(str_ua_result,128,"%s-%s", str_UA_file_position, str_result);
-               }
-               vconf_result = vconf_set_str(UA_RESULT_KEY, str_ua_result);
-               if(vconf_result == 0) {
-                       _DEBUG_VERBOSE("vconf_set_str() success %s [%s]!!", UA_RESULT_KEY, str_ua_result);
-               } else {
-                       _DEBUG_VERBOSE("vconf_set_str() %s failed !!", UA_RESULT_KEY);
-               }
-       }
-
        _DEBUG_INFO("str_result [%s] \n", str_result);
 
-       if (str_result != NULL)
-               free(str_result);
-
        if (file_des != NULL)
                fclose(file_des);
 
        _EXTERN_FUNC_EXIT;
+       return str_result;
 }
 
 int slp_device_ctrl_get_fota_update_result()
@@ -217,10 +194,16 @@ int slp_device_ctrl_get_fota_update_result()
 
        int update_result = 400;
        FILE *file_des;
-       long lSize = 0;         /*prevent */
+       long lSize = 0;
+       long file_data_size = 0;
        size_t result;
        //file_des = fopen("/opt/result", "rb");
        char file_path[128] = {0,};
+
+       char * str_cause = NULL;
+       int vconf_result = 0;
+       char str_result_merge[128] = {0,};
+
        snprintf(file_path,128, "%s/result", /*FOTA_SAVE_DIR*/ "/opt/usr/data/fota/save");
        file_des = fopen(file_path, "rb");
 
@@ -266,27 +249,58 @@ int slp_device_ctrl_get_fota_update_result()
                _EXTERN_FUNC_EXIT;
                return 400;
        }
-       if (str_result[lSize - 1] == '\n')
+       if (str_result[lSize - 1] == '\n') {
                str_result[lSize - 1] = 0;
+               file_data_size = lSize -1;
+       } else {
+               file_data_size = lSize;
+       }
 
        for (j = 0; j < RB_ERR_CODE_MAX_COUNT; j++) {
-               if (strlen(str_result) == strlen(redbend_omadm_table[j].result_redbend)) {
+               //if (strlen(str_result) == strlen(redbend_omadm_table[j].result_redbend)) {
+               if (file_data_size == strlen(redbend_omadm_table[j].result_redbend)) {
                        if ((strcmp(str_result, redbend_omadm_table[j].result_redbend) == 0)) {
                                update_result = redbend_omadm_table[j].result_code;
                                match_found = true;
-                               _DEBUG_INFO("Result info [%s] \n", redbend_omadm_table[j].str_redbend);
-
-                               if(update_result != 200) {
-                                       slp_device_ctrl_get_fota_fail_ua_result(redbend_omadm_table[j].str_redbend);
+                               _DEBUG_INFO("Result meanning info [%s] \n", redbend_omadm_table[j].str_meanning);
+
+                               ////////////////////////////////////////////////////////////////////////////////
+                               if(redbend_omadm_table[j].str_redbend != NULL) {
+                                       str_cause = slp_device_ctrl_get_fota_fail_ua_result();
+                                       if(str_cause == NULL) {
+                                               vconf_result = vconf_set_str(UA_RESULT_KEY, redbend_omadm_table[j].str_meanning);
+                                               if(vconf_result == 0) {
+                                                       _DEBUG_VERBOSE("vconf_set_str() success %s [%s]!!", UA_RESULT_KEY, redbend_omadm_table[j].str_meanning);
+                               } else {
+                                                       _DEBUG_VERBOSE("vconf_set_str() %s failed !!", UA_RESULT_KEY);
+                                               }
+                                       } else {
+                                               if( strlen(str_cause) > 0 ) {
+                                                       snprintf(str_result_merge, 120, "%s - %s", redbend_omadm_table[j].str_meanning, str_cause);
+                                                       vconf_result = vconf_set_str(UA_RESULT_KEY, str_result_merge);
+                                                       if(vconf_result == 0) {
+                                                               _DEBUG_VERBOSE("vconf_set_str() success %s [%s]!!", UA_RESULT_KEY, str_result_merge);
+                                                       } else {
+                                                               _DEBUG_VERBOSE("vconf_set_str() %s failed !!", UA_RESULT_KEY);
+                                                       }
+                                               } else {
+                                                       vconf_result = vconf_set_str(UA_RESULT_KEY, redbend_omadm_table[j].str_meanning);
+                                                       if(vconf_result == 0) {
+                                                               _DEBUG_VERBOSE("vconf_set_str() success %s [%s]!!", UA_RESULT_KEY, redbend_omadm_table[j].str_meanning);
+                                                       } else {
+                                                               _DEBUG_VERBOSE("vconf_set_str() %s failed !!", UA_RESULT_KEY);
+                                                       }
+                                               }
+                                       }
                                } else {
-                                       int vconf_result = 0;
-                                       vconf_result = vconf_set_str(UA_RESULT_KEY, redbend_omadm_table[j].str_redbend);
+                                       vconf_result = vconf_set_str(UA_RESULT_KEY, redbend_omadm_table[j].str_meanning);
                                        if(vconf_result == 0) {
-                                               _DEBUG_VERBOSE("vconf_set_str() success %s [%s]!!", UA_RESULT_KEY, redbend_omadm_table[j].str_redbend);
+                                               _DEBUG_VERBOSE("vconf_set_str() success %s [%s]!!", UA_RESULT_KEY, redbend_omadm_table[j].str_meanning);
                                        } else {
                                                _DEBUG_VERBOSE("vconf_set_str() %s failed !!", UA_RESULT_KEY);
                                        }
                                }
+                               ////////////////////////////////////////////////////////////////////////////////
 
                                break;  /* If existing error code, break-out from the for-loop. */
                        }
@@ -295,6 +309,18 @@ int slp_device_ctrl_get_fota_update_result()
                        update_result = 410;
        }
 
+       if(!match_found) {
+               vconf_result = vconf_set_str(UA_RESULT_KEY, "No find");
+               if(vconf_result == 0) {
+                       _DEBUG_VERBOSE("vconf_set_str() success %s [%s]!!", UA_RESULT_KEY, "No find");
+               } else {
+                       _DEBUG_VERBOSE("vconf_set_str() %s failed !!", UA_RESULT_KEY);
+               }
+       }
+
+
+       if(str_cause != NULL)
+               free(str_cause);
        if (str_result != NULL)
                free(str_result);