Replace the sscanf function 87/127487/2 accepted/tizen/unified/20170428.033207 submit/tizen/20170428.004210 tizen_4.0.m1_release
authorHyuk Lee <hyuk0512.lee@samsung.com>
Thu, 27 Apr 2017 11:43:50 +0000 (20:43 +0900)
committerHyuk Lee <hyuk0512.lee@samsung.com>
Thu, 27 Apr 2017 11:45:33 +0000 (20:45 +0900)
Change-Id: I08fd8228137dfbc8c554b7e9fb2e5332bce81053
Signed-off-by: Hyuk Lee <hyuk0512.lee@samsung.com>
bt-ipsp/bt-ipsp.c
hf-agent/bluetooth-hf-agent.c
map-agent/bluetooth_map_agent.c

index db46b87..17ce2af 100644 (file)
@@ -484,7 +484,14 @@ static void __generate_eui64_address(char *hw_addr, char **eui64_addr)
 
        for (i = 0; i < 6; i++) {
                strtok_r(copied, ":", &ptr);
-               sscanf(copied, "%s", addr[i]);
+               if (sizeof(addr[i]) <= strlen(copied)) {
+                       strncpy(addr[i], copied, sizeof(addr[i]) - 1);
+                       addr[i][(int)(sizeof(addr[i]) - 1)] = '\0';
+               } else {
+                       strncpy(addr[i], copied, strlen(copied));
+                       addr[i][(int)strlen(copied)] = '\0';
+               }
+
                BT_DBG("copied/ptr (%s/%s)", copied, ptr);
                BT_DBG("addr(%s)", addr[i]);
                copied = ptr;
index 8cade59..048ae4a 100755 (executable)
@@ -1052,7 +1052,8 @@ static int __bt_hf_agent_handle_ccwa(bt_hf_agent_info_t *bt_hf_info,
 {
        GDBusConnection *conn;
        gchar *ccwa;
-       gchar number[BT_HF_CALLER_NUM_SIZE];
+       gchar *number;
+       gchar *ptr;
        gchar *sep;
        char fmt_str[BT_HF_FMT_STR_SIZE];
        int len = strlen(buf);
@@ -1065,8 +1066,9 @@ static int __bt_hf_agent_handle_ccwa(bt_hf_agent_info_t *bt_hf_info,
 
        if ((ccwa = strstr(buf, "\r\n+CCWA"))) {
                snprintf(fmt_str, sizeof(fmt_str), "\r\n+CCWA: \"%%%ds",
-                                                                       (int)(sizeof(number) - 1));
-               if (sscanf(ccwa, fmt_str, number) == 1) {
+                                                                       BT_HF_CALLER_NUM_SIZE - 1);
+               if ((ptr = strstr(ccwa, "\"")) != NULL) {
+                       number = ptr + 1;
                        sep = strchr(number, '"');
                        sep[0] = '\0';
 
@@ -1098,6 +1100,7 @@ static GSList *__bt_hf_prepare_call_list(const char *buf)
        char *ptr = NULL;
        char *temp = NULL;
        char *sp;
+       char *stop;
        char delim_sep[] = "\r\n";
        char temp_buf[BT_HF_DATA_BUF_SIZE] = {0,};
 
@@ -1115,13 +1118,18 @@ static GSList *__bt_hf_prepare_call_list(const char *buf)
 
                call_info = g_new0(hf_call_list_info_t, 1);
 
-               sscanf(str, "+CLCC: %1d,%1d, %1d, %1d, %1d",
-                               &call_info->idx, &call_info->dir,
-                               &call_info->status, &call_info->mode,
-                               &call_info->multi_party);
-               DBG("Index = [%d], Direction = [%d], Status = [%d], Mode = [%d], Multi_party = [%d]\n",
-                               call_info->idx, call_info->dir, call_info->status,
-                               call_info->mode, call_info->multi_party);
+               /* str format : "+CLCC: %1d,%1d, %1d, %1d, %1d" */
+               if ((ptr = strchr(str, ':')) != NULL) {
+                       call_info->idx = strtol(ptr + 1, &stop, 10);
+                       call_info->dir = strtol(stop + 1, &stop, 10);
+                       call_info->status = strtol(stop + 1, &stop, 10);
+                       call_info->mode = strtol(stop + 1, &stop, 10);
+                       call_info->multi_party = strtol(stop + 1, &stop, 10);
+
+                       DBG("Index = [%d], Direction = [%d], Status = [%d], Mode = [%d], Multi_party = [%d]\n",
+                                       call_info->idx, call_info->dir, call_info->status,
+                                       call_info->mode, call_info->multi_party);
+               }
 
                ptr = strstr(str, "\"");
                if (ptr) {
@@ -1487,8 +1495,9 @@ done:
 
 static int __bt_hf_agent_handler_ciev(bt_hf_agent_info_t *bt_hf_info, const char *buf)
 {
-       gchar indicator[BT_HF_INDICATOR_DESCR_SIZE + 4];
+       gchar *indicator;
        gchar *sep;
+       gchar *ptr;
        gint value;
        guint index;
        char fmt_str[BT_HF_FMT_STR_SIZE];
@@ -1496,8 +1505,9 @@ static int __bt_hf_agent_handler_ciev(bt_hf_agent_info_t *bt_hf_info, const char
        DBG("++++++++ __bt_hf_agent_handler_ciev +++++++++");
 
        snprintf(fmt_str, sizeof(fmt_str), "\r\n+CIEV:%%%ds\r\n",
-                                                               (int)(sizeof(indicator) - 1));
-       if (sscanf(buf, fmt_str, indicator) == 1) {
+                                                               BT_HF_INDICATOR_DESCR_SIZE + 4 - 1);
+       if ((ptr = strchr(buf, ':')) != NULL) {
+               indicator = ptr + 1;
                sep = strchr(indicator, ',');
                sep[0] = '\0';
                sep += 1;
@@ -1556,8 +1566,12 @@ static int __bt_hf_agent_handler_bvra(bt_hf_agent_info_t *bt_hf_info, const char
 {
        DBG("+++++++++ __bt_hf_agent_handler_bvra +++++++++");
        gint value;
-        if (sscanf(buf, "\r\n+BVRA:%1d\r\n", &value) == 1)
+       gchar *ptr;
+       gchar *stop;
+       if ((ptr = strstr(buf, "BVRA:")) != NULL) {
+               value = strtol(ptr + 5, &stop, 10);
                __bt_hf_agent_handle_voice_activation(value);
+       }
 
         DBG("---------__bt_hf_agent_handler_bvra --------");
        return 0;
@@ -1566,9 +1580,13 @@ static int __bt_hf_agent_handler_bvra(bt_hf_agent_info_t *bt_hf_info, const char
 static int __bt_hf_agent_handler_bcs(bt_hf_agent_info_t *bt_hf_info, const char *buf)
 {
        guint codec_id;
+       gchar *ptr;
+       gchar *stop;
        DBG("+++++++++ __bt_hf_agent_handler_bcs +++++++++-");
-       if (sscanf(buf, "\r\n+BCS:%3d\r\n", &codec_id))
+       if ((ptr = strstr(buf, "BCS:")) != NULL) {
+               codec_id = strtol(ptr + 4, &stop, 10);
                __bt_hf_agent_handle_codec_select(bt_hf_info, codec_id);
+       }
 
        DBG("---------__bt_hf_agent_handler_bcs --------");
        return 0;
@@ -1577,9 +1595,13 @@ static int __bt_hf_agent_handler_bcs(bt_hf_agent_info_t *bt_hf_info, const char
 static int __bt_hf_agent_handler_vgs(bt_hf_agent_info_t *bt_hf_info, const char *buf)
 {
        gint value;
+       gchar *ptr;
+       gchar *stop;
        DBG("+++++++++ __bt_hf_agent_handler_vgs +++++++++");
-       if (sscanf(buf, "\r\n+VGS:%2d\r\n", &value))
+       if ((ptr = strstr(buf, "VGS:")) != NULL) {
+               value = strtol(ptr + 4, &stop, 10);
                __bt_hf_agent_handle_speaker_gain(value);
+       }
 
        DBG("---------__bt_hf_agent_handler_vgs --------");
 
@@ -1599,14 +1621,24 @@ static int __bt_hf_agent_handler_ccwa(bt_hf_agent_info_t *bt_hf_info, const char
 static int __bt_hf_agent_handler_xsat(bt_hf_agent_info_t *bt_hf_info,
                                                        const char *buf)
 {
-       gint app_id;
-       char msg[BT_HF_DATA_BUF_SIZE];
+       gint app_id = 0;
+       char *msg = NULL;
        char fmt_str[BT_HF_CMD_BUF_SIZE];
+       char *ptr = NULL;
+       char *save_ptr = NULL;
+       char *stop = NULL;
 
        DBG("+++++++++ __bt_hf_agent_handler_xsat +++++++++");
        snprintf(fmt_str, sizeof(fmt_str), "\r\n+XSAT:%%d,%%%ds\r\n",
                                                                                (int)(sizeof(msg) - 1));
-       if (sscanf(buf, fmt_str, &app_id, msg)) {
+       ptr = strstr(buf, "XSAT:");
+       if (ptr)
+               app_id = strtol(ptr + 5, &stop, 10);
+
+       if (stop)
+               msg = strtok_r(stop + 1, "\\", &save_ptr);
+
+       if (app_id || msg) {
                if (app_id == 2 && strstr(msg, "READTXPOWER")) {
                        char cmd_buf[BT_HF_CMD_BUF_SIZE * 2] = {0, };
                        char power = __bt_hf_agent_get_tx_power(bt_hf_info->remote_addr);
@@ -2217,11 +2249,12 @@ static GSList *__bt_hf_parse_indicator_values(gchar *values, GSList *indices)
        GSList *runner = indices;
 
        gchar *cur = values - 1;
+       gchar *stop;
        DBG("Indicator string = %s", values);
        __bt_hf_agent_print_at_buffer("Indicator values :", values);
        while (cur != NULL) {
                cur += 1;
-               sscanf(cur, "%1d", &val);
+               val = strtol(cur, &stop, 10);
                cur = strchr(cur, ',');
                ind = g_slist_nth_data(runner, 0);
                ind->value = val;
@@ -2546,6 +2579,7 @@ static gboolean __bt_establish_service_level_conn(bt_hf_agent_info_t *bt_hf_info
        gchar cmd_buf[BT_HF_CMD_BUF_SIZE] = {0};
        gboolean ret;
        char *buf_ptr;
+       char *stop;
        guint feature = BT_HF_FEATURE_EC_ANDOR_NR |
                        BT_HF_FEATURE_CALL_WAITING_AND_3WAY |
                        BT_HF_FEATURE_CLI_PRESENTATION |
@@ -2567,7 +2601,11 @@ static gboolean __bt_establish_service_level_conn(bt_hf_agent_info_t *bt_hf_info
        if (buf_ptr == NULL)
                return FALSE;
 
-       if (!ret || sscanf(buf_ptr, "\r\n+BRSF:%5d", &bt_hf_info->ag_features) != 1)
+       buf_ptr = strstr(buf_ptr, "BRSF:");
+       bt_hf_info->ag_features = strtol(buf_ptr + 5, &stop, 10);
+
+
+       if (!ret || !bt_hf_info->ag_features)
                return FALSE;
        INFO("Gateway supported features are 0x%X", bt_hf_info->ag_features);
 
index 2d18a2c..77c61e7 100644 (file)
@@ -595,9 +595,24 @@ time_t _get_time_t_from_timestamp(char *timestamp)
        int month;
        time_t int_time;
 
-       sscanf(timestamp, "%04d%02d%02dT%02d%02d%02d", &year, &month,
-                       &local_time.tm_mday, &local_time.tm_hour,
-                       &local_time.tm_min, &local_time.tm_sec);
+       int ymd; /* year, month, day */
+       int hms; /* hour, min, sec */
+       char *ptr, *ptr2;
+
+       ymd = strtol(timestamp, &ptr, 10);
+       hms = strtol(ptr + 1, &ptr2, 10);
+
+       /* parse year, month, day */
+       local_time.tm_mday = ymd % 100;
+       ymd = (ymd - local_time.tm_mday) / 100;
+       month = ymd % 100;
+       year = (ymd - month) / 100;
+
+       /* parse hour, minute, sec */
+       local_time.tm_sec = hms % 100;
+       hms = (hms - local_time.tm_sec) / 100;
+       local_time.tm_min = hms % 100;
+       local_time.tm_hour = (hms - local_time.tm_min) / 100;
 
        local_time.tm_year = year - 1900;
        local_time.tm_mon = month - 1;