From b08092dd6a3cc7a7a66ad3192553d9f6f03018ba Mon Sep 17 00:00:00 2001 From: alkasethi Date: Wed, 16 Jan 2019 20:31:02 +0530 Subject: [PATCH] [SATDEVKIT-2522]Symbolic link issues handled Change-Id: I02fd9d7b139c7efc6f83ecfd3f87876e4091a9c2 Signed-off-by: alkasethi --- src/plugin.c | 40 ++++++++++++++++++++++++---------------- src/sdb.c | 18 +++++++++++++++--- src/services.c | 5 ++++- 3 files changed, 43 insertions(+), 20 deletions(-) diff --git a/src/plugin.c b/src/plugin.c index 3c2533c..97bb86f 100644 --- a/src/plugin.c +++ b/src/plugin.c @@ -388,7 +388,7 @@ int request_capability_to_plugin ( int cap, char* out_buf, unsigned int out_len ret = request_sync_cmd ( PLUGIN_SYNC_CMD_CAPABILITY, &in, &out ); if ( ret == PLUGIN_CMD_SUCCESS ) { - if(out.array_of_parameter[0].v_string.data != NULL) { + if ( out.array_of_parameter != NULL && out.array_of_parameter[0].v_string.data != NULL) { strncpy ( out_buf, out.array_of_parameter[0].v_string.data, out_len - 1 ); out_buf[out_len - 1] = '\0'; success = 1; @@ -429,8 +429,10 @@ int request_validity_to_plugin ( int cmd, const char* in_buf ) ret = request_sync_cmd ( cmd, &in, &out ); if ( ret == PLUGIN_CMD_SUCCESS ) { - success = ( out.array_of_parameter[0].v_int32 == PLUGIN_RET_VALID ) ? 1 : 0; - release_parameters ( &out ); + if (out.array_of_parameter != NULL) { + success = ( out.array_of_parameter[0].v_int32 == PLUGIN_RET_VALID ) ? 1 : 0; + release_parameters ( &out ); + } D ("request validity success : %d\n", success); } @@ -468,8 +470,10 @@ int request_extcmd_validity_to_plugin ( int cmd, const char* in_buf) out.array_of_parameter = NULL; ret = plugin_sync_proc ( cmd, &in, &out ); if ( ret == PLUGIN_CMD_SUCCESS ) { - success = ( out.array_of_parameter[0].v_int32 == PLUGIN_RET_VALID ) ? 1 : 0; - release_parameters ( &out ); + if (out.array_of_parameter != NULL) { + success = ( out.array_of_parameter[0].v_int32 == PLUGIN_RET_VALID ) ? 1 : 0; + release_parameters ( &out ); + } D ("request validity success : %d\n", success); } @@ -503,7 +507,7 @@ int request_conversion_to_plugin ( int cmd, const char* in_buf, char* out_buf, u ret = request_sync_cmd ( cmd, &in, &out ); if ( ret == PLUGIN_CMD_SUCCESS ) { - if(out.array_of_parameter[0].v_string.data != NULL) { + if(out.array_of_parameter != NULL && out.array_of_parameter[0].v_string.data != NULL) { strncpy ( out_buf, out.array_of_parameter[0].v_string.data, out_len - 1 ); out_buf[out_len - 1] = '\0'; success = 1; @@ -543,7 +547,7 @@ int request_extcmd_conversion_to_plugin ( int cmd, const char* in_buf, char* out ret = plugin_sync_proc ( cmd, &in, &out ); if ( ret == PLUGIN_CMD_SUCCESS ) { - if(out.array_of_parameter[0].v_string.data != NULL) { + if (out.array_of_parameter != NULL && out.array_of_parameter[0].v_string.data != NULL) { strncpy ( out_buf, out.array_of_parameter[0].v_string.data, out_len - 1 ); out_buf[out_len - 1] = '\0'; success = 1; @@ -575,13 +579,15 @@ int request_lock_state_to_plugin ( int lock_type ) ret = request_sync_cmd ( PLUGIN_SYNC_CMD_GET_LOCK_STATE, &in, &out ); if ( ret == PLUGIN_CMD_SUCCESS ) { - if ( out.array_of_parameter[0].v_int32 == PLUGIN_RET_ON ) { - result = 1; - } else { - result = 0; - } - is_pwlocked = result; - release_parameters ( &out ); + if (out.array_of_parameter != NULL) { + if ( out.array_of_parameter[0].v_int32 == PLUGIN_RET_ON ) { + result = 1; + } else { + result = 0; + } + is_pwlocked = result; + release_parameters ( &out ); + } } release_parameters ( &in ); @@ -616,8 +622,10 @@ int request_handlecmd_to_plugin ( int cmd, const char* in_buf ) ret = request_sync_cmd ( cmd, &in, &out ); if ( ret == PLUGIN_CMD_SUCCESS ) { - success = ( out.array_of_parameter[0].v_int32 == PLUGIN_RET_HANDLE ) ? 1 : 0; - release_parameters ( &out ); + if (out.array_of_parameter != NULL) { + success = ( out.array_of_parameter[0].v_int32 == PLUGIN_RET_HANDLE ) ? 1 : 0; + release_parameters ( &out ); + } D ("request command handling success : %d\n", success); } diff --git a/src/sdb.c b/src/sdb.c index ba6e1ac..4640136 100644 --- a/src/sdb.c +++ b/src/sdb.c @@ -1313,10 +1313,22 @@ static void booting_done_signal_subscriber(GDBusConnection *connection, } else { FILE *info_file = fopen(SDBD_BOOT_INFO_FILE, "w"); if (info_file != NULL) { - fprintf(info_file, "%d", 1); - fclose(info_file); + char* tmppath = realpath(SDBD_BOOT_INFO_FILE, NULL); + if (tmppath != NULL) { + if (strcmp(SDBD_BOOT_INFO_FILE, tmppath) == 0) { + fprintf(info_file, "%d", 1); + I("booting is done\n"); + } else { + D("Path has symbolic link, security risk \n"); + free(tmppath); + return; + } + free(tmppath); + } else { + D("Getting realpath failed\n"); + } + fclose(info_file); } - I("booting is done\n"); } I("handled the booting done signal\n"); diff --git a/src/services.c b/src/services.c index db9148e..284db2c 100644 --- a/src/services.c +++ b/src/services.c @@ -1412,7 +1412,7 @@ int request_extcmd_to_plugin(const char* in_buf) { int cmd = atoi(cmd_no); char* exec_type = tokens[args_cnt - 1]; - if (strlen(cmd_name) >= ENV_BUF_MAX) { + if (strlen(full_cmd) + strlen(cmd_name) + 1 >= ENV_BUF_MAX) { strncat(full_cmd, cmd_name, ENV_BUF_MAX - 1); full_cmd[ENV_BUF_MAX - 1] = '\0'; } @@ -1422,6 +1422,9 @@ int request_extcmd_to_plugin(const char* in_buf) { int i = 1; for(;i < args_cnt - 2;i++) { + if (tokens[i] == NULL){ + continue; + } if (strlen(full_cmd) + strlen(tokens[i]) + 1 >= ENV_BUF_MAX) { break; } -- 2.34.1