From 8da90c78f1150548d8950e86652c9973fd80bc58 Mon Sep 17 00:00:00 2001 From: Vitaliy Cherepanov Date: Mon, 5 Aug 2013 19:54:02 +0400 Subject: [PATCH] [FIX] fix segmentation fault on GetTargetInfo message --- daemon/da_protocol.c | 8 +++++--- daemon/daemon.h | 2 +- daemon/main.c | 2 +- daemon/sys_stat.c | 42 +++++++++++++++++++++++++++--------------- daemon/sys_stat.h | 3 ++- 5 files changed, 36 insertions(+), 21 deletions(-) diff --git a/daemon/da_protocol.c b/daemon/da_protocol.c index 4d5555a..9af205e 100644 --- a/daemon/da_protocol.c +++ b/daemon/da_protocol.c @@ -692,7 +692,7 @@ static void reset_app_info(struct app_info_t *app_info) static void reset_target_info(struct target_info_t *target_info) { - free(target_info->network_type); + return; } static void reset_conf(struct conf_t *conf) @@ -826,8 +826,8 @@ static struct msg_t *gen_target_info_reply(struct target_info_t *target_info) p = msg->payload; pack_int(p, ret_id); - pack_int(p, target_info->sys_mem_size); - pack_int(p, target_info->storage_size); + pack_int64(p, target_info->sys_mem_size); + pack_int64(p, target_info->storage_size); pack_int(p, target_info->bluetooth_supp); pack_int(p, target_info->gps_supp); pack_int(p, target_info->wifi_supp); @@ -843,6 +843,7 @@ static struct msg_t *gen_target_info_reply(struct target_info_t *target_info) static int send_reply(struct msg_t *msg) { + printBuf(msg, msg->len + sizeof (*msg)); if (send(manager.host.control_socket, msg, MSG_CMD_HDR_LEN + msg->len, MSG_NOSIGNAL) == -1) { LOGE("Cannot send reply : %s\n", strerror(errno)); @@ -1090,6 +1091,7 @@ int host_message_handler(struct msg_t *msg) fill_target_info(&target_info); msg_reply = gen_target_info_reply(&target_info); if (!msg_reply) { + LOGE("cannot generate reply message\n"); sendACKToHost(msg->id, ERR_UNKNOWN, 0, 0); return -1; } diff --git a/daemon/daemon.h b/daemon/daemon.h index 47bded4..a2b55be 100644 --- a/daemon/daemon.h +++ b/daemon/daemon.h @@ -185,9 +185,9 @@ typedef struct int brightness; int video; int voltage; + int procmeminfo; FILE *audio_status; FILE *procstat; - FILE *procmeminfo; FILE *networkstat; FILE *diskstats; } __file_descriptors; diff --git a/daemon/main.c b/daemon/main.c index e029e08..6335cf7 100644 --- a/daemon/main.c +++ b/daemon/main.c @@ -88,9 +88,9 @@ __da_manager manager = .brightness = -1, .video = -1, .voltage = -1, + .procmeminfo = -1, .audio_status = NULL, .procstat = NULL, - .procmeminfo = NULL, .networkstat = NULL, .diskstats = NULL }, diff --git a/daemon/sys_stat.c b/daemon/sys_stat.c index cf3478f..1c0af63 100644 --- a/daemon/sys_stat.c +++ b/daemon/sys_stat.c @@ -1699,10 +1699,11 @@ int get_camera_count() static int get_device_network_type(char* buf, int buflen) { int len = 0; + char *p = buf; bool bool_var; system_info_get_platform_bool("tizen.org/feature/network.telephony.service.cdma", &bool_var); - if(bool_var) len += sprintf(buf + len, "CDMA"); + if(bool_var) len += sprintf(buf + len, ",CDMA"); system_info_get_platform_bool("tizen.org/feature/network.telephony.service.edge", &bool_var); if(bool_var) len += sprintf(buf + len, ",EDGE"); system_info_get_platform_bool("tizen.org/feature/network.telephony.service.gprs", &bool_var); @@ -1720,6 +1721,10 @@ static int get_device_network_type(char* buf, int buflen) system_info_get_platform_bool("tizen.org/feature/network.telephony.service.lte", &bool_var); if(bool_var) len += sprintf(buf + len, ",LTE"); + if (len != 0) { + memcpy(p, p + 1, len + 1); + len--; + } return len; } @@ -2498,27 +2503,33 @@ int finalize_system_info() } -void test_and_close(int fd) +inline void tac(int fd) { - if (fd != 0) + if (fd > 0) close(fd); + fd = -1; } -void ftest_and_close(FILE *fd) +inline void ftac(FILE *fd) { if (fd != NULL) fclose(fd); + fd = NULL; } +#define strr(x) #x +#define str(x) strr(x) +#define test_and_close(fd) do {LOGI("CLOSE " str(fd) "\n");tac(fd);} while(0) +#define ftest_and_close(fd) do {LOGI("CLOSE " str(fd) "\n");ftac(fd);} while(0) void close_system_file_descriptors() { test_and_close(manager.fd.brightness); test_and_close(manager.fd.video); test_and_close(manager.fd.voltage); + test_and_close(manager.fd.procmeminfo); ftest_and_close(manager.fd.audio_status); ftest_and_close(manager.fd.procstat); - ftest_and_close(manager.fd.procmeminfo); ftest_and_close(manager.fd.networkstat); ftest_and_close(manager.fd.diskstats); } @@ -2529,9 +2540,9 @@ int init_system_file_descriptors() init_brightness_status(); init_video_status(); init_voltage_status(); + init_update_system_memory_data(); init_audio_status(); init_system_cpu_data(); - init_update_system_memory_data(); init_network_stat(); init_disk_stat(); @@ -2541,16 +2552,16 @@ int init_system_file_descriptors() LOGE("video file not found\n"); if (manager.fd.voltage < 0) LOGE("voltage file not found\n"); - if (manager.fd.audio_status < 0) - LOGE("audio file not found\n"); - if (manager.fd.procstat < 0) - LOGE("procstat file not found\n"); if (manager.fd.procmeminfo < 0) LOGE("procmeminfo file not found\n"); - if (manager.fd.networkstat < 0) + if (manager.fd.audio_status == NULL) + LOGE("audio file not found\n"); + if (manager.fd.procstat == NULL) + LOGE("procstat file not found\n"); + if (manager.fd.networkstat == NULL) LOGE("networkstat file not found\n"); - if (manager.fd.diskstats < 0) - LOGE("difostat file not found\n"); + if (manager.fd.diskstats == NULL) + LOGE("diskstat file not found\n"); return 0; } @@ -2563,7 +2574,7 @@ int fill_target_info(struct target_info_t *target_info) target_info->gps_supp = 0; target_info->wifi_supp = 0; target_info->camera_count = 0; - target_info->network_type = 0; + target_info->network_type[0] = 0; target_info->sys_mem_size = get_system_total_memory(); target_info->storage_size = stat_get_storageinfo(FSINFO_TYPE_TOTAL) * @@ -2581,7 +2592,8 @@ int fill_target_info(struct target_info_t *target_info) (_Bool *)&target_info->wifi_supp); target_info->camera_count = get_camera_count(); - get_device_network_type(target_info->network_type, 128); + + get_device_network_type(target_info->network_type, NWTYPE_SIZE); #endif /* LOCALTEST */ diff --git a/daemon/sys_stat.h b/daemon/sys_stat.h index 1c9de8b..25dd892 100644 --- a/daemon/sys_stat.h +++ b/daemon/sys_stat.h @@ -76,6 +76,7 @@ extern "C" { #define FSINFO_TYPE_TOTAL 1 #define FSINFO_TYPE_FREE 2 +#define NWTYPE_SIZE 128 #define MAXNAMESIZE 16 #include @@ -144,7 +145,7 @@ struct target_info_t { uint32_t gps_supp; uint32_t wifi_supp; uint32_t camera_count; - char *network_type; + char network_type[NWTYPE_SIZE]; uint32_t max_brightness; uint32_t cpu_core_count; }; -- 2.7.4