From: Sooyoung Ha Date: Wed, 9 Jan 2013 17:27:43 +0000 (+0900) Subject: [Title] fix prevent defects on libvmodem/libvgsm_sim.c X-Git-Tag: accepted/tizen/common/20150529.082310~8^2~31^2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=c6420148c334543679df96e0e68d75e308974359;p=platform%2Fadaptation%2Femulator%2Fvmodem-daemon-emulator.git [Title] fix prevent defects on libvmodem/libvgsm_sim.c [Desc.] Resource leak and null check [Issue] Prevent CID 33405, 33818~22, 33907~10 --- diff --git a/libvmodem/libvgsm_sim.c b/libvmodem/libvgsm_sim.c index 40f1d17..0e06e43 100644 --- a/libvmodem/libvgsm_sim.c +++ b/libvmodem/libvgsm_sim.c @@ -174,14 +174,16 @@ int vgsm_get_all_pb_db(LXT_HANDLE * handle, gsm_pb_storage_type_e_type storage_ { printf("[LIBVGSM-SIM] vgsm_get_pb_db\n"); + if( handle == NULL ||(int) storage_type < 0 || storage_type > GSM_PB_ST_GAS ) + return -1; + PB_ *pb; pb = malloc(sizeof(PB_)); + if(!pb) + return -1; memset(pb,0,sizeof(PB_)); int ret; - if( handle == NULL ||(int) storage_type < 0 || storage_type > GSM_PB_ST_GAS ) - return -1; - pb->db_st_type = storage_type; printf("vgsm_get_all_pb_db : %d ",pb->db_st_type); @@ -205,14 +207,16 @@ int vgsm_get_pb_db(LXT_HANDLE * handle, gsm_pb_storage_type_e_type storage_type, { printf("[LIBVGSM-SIM] vgsm_get_pb_db\n"); + if( handle == NULL ||(int)storage_type < 0 || storage_type > GSM_PB_ST_GAS ) + return -1; + PB_ *pb; pb = malloc(sizeof(PB_)); + if(!pb) + return -1; memset(pb,0,sizeof(PB_)); int ret; - if( handle == NULL ||(int)storage_type < 0 || storage_type > GSM_PB_ST_GAS ) - return -1; - pb->db_st_type = storage_type; //pb->index = atoi(index_); memcpy(pb->address,index_,strlen(index_)); @@ -239,14 +243,16 @@ int vgsm_add_pb_db(LXT_HANDLE * handle, gsm_pb_storage_type_e_type storage_type, { printf("[LIBVGSM-SIM] vgsm_add_pb_db\n"); + if( handle == NULL ||(int)storage_type < 0 || storage_type > GSM_PB_ST_GAS ) + return -1; + PB_ *pb; - pb = malloc(sizeof(PB_)); int ret; - memset(pb,0,sizeof(PB_)); - - if( handle == NULL ||(int)storage_type < 0 || storage_type > GSM_PB_ST_GAS ) + pb = malloc(sizeof(PB_)); + if(!pb) return -1; + memset(pb,0,sizeof(PB_)); printf(" \n** 1 **"); pb->db_st_type = storage_type; @@ -276,14 +282,16 @@ int vgsm_delete_pb_db(LXT_HANDLE * handle, gsm_pb_storage_type_e_type storage_ty { printf("[LIBVGSM-SIM] vgsm_delete_pb_db\n"); + if( handle == NULL ||(int)storage_type < 0 || storage_type > GSM_PB_ST_GAS ) + return -1; + PB_ *pb; pb = malloc(sizeof(PB_)); + if(!pb) + return -1; int ret; memset(pb,0,sizeof(PB_)); - if( handle == NULL ||(int)storage_type < 0 || storage_type > GSM_PB_ST_GAS ) - return -1; - pb->db_st_type = storage_type; //pb->index = atoi(index_); memcpy(pb->name,index_,strlen(index_)); @@ -329,33 +337,42 @@ int vgsm_sim_change_password(LXT_HANDLE * handle, gsm_sec_lock_e_type type, char { printf("[LIBVGSM-SIM] vgsm_sim_change_password\n"); + if( handle == NULL ) + return -1; + //if ( type != GSM_SEC_LOCK_TYPE_SC && type != GSM_SEC_LOCK_TYPE_SC2 ) // original before 090215 //090215 if ( type != GSM_SEC_LOCK_TYPE_SC && type != GSM_SEC_LOCK_TYPE_SC2 && type != GSM_SEC_LOCL_TYPE_PUK2 && type != GSM_SEC_LOCL_TYPE_PUK) return -1; + int ret = -1; char *new_password=0; new_password = malloc(length + 1); // 1 <= type - if(!new_password) + if(!new_password){ printf("memory alloc err"); + return ret; + } new_password[0] = (char)type; memcpy(&new_password[1],password,length); printf(" [LIBVGSM-SIM] input password =[%s] \n\n",&new_password[1]); - if( handle == NULL ) - return -1; - - return lxt_msg_send_message +/* return lxt_msg_send_message ( handle->fd, GSM_SIM, GSM_SIM_CHANGE_PASS_SET, length+1, new_password - ); + ); modify to free new_password and use ret */ + ret = lxt_msg_send_message(handle->fd, GSM_SIM, GSM_SIM_CHANGE_PASS_SET, length+1, new_password); + + if(new_password) + free(new_password); + + return ret; } diff --git a/packaging/vmodemd-emul.spec b/packaging/vmodemd-emul.spec index eed4be5..62f8d91 100644 --- a/packaging/vmodemd-emul.spec +++ b/packaging/vmodemd-emul.spec @@ -1,6 +1,6 @@ #git:slp/pkgs/v/vmodem-daemon-emulator Name: vmodemd-emul -Version: 0.2.26 +Version: 0.2.27 Release: 1 Summary: Modem Emulator Group: System/ModemEmulator