Fix SVACE defects 20/172320/1 accepted/tizen/unified/20180316.062436 submit/tizen/20180313.074314
authorSeungbae Shin <seungbae.shin@samsung.com>
Tue, 13 Mar 2018 07:38:16 +0000 (16:38 +0900)
committerSeungbae Shin <seungbae.shin@samsung.com>
Tue, 13 Mar 2018 07:38:24 +0000 (16:38 +0900)
[Version] 0.12.12
[Issue Type] Security

Change-Id: Id681c147e6b346e7391e0f635d5ff92d49ca6b48

testsuite/mm_sound_testsuite_simple.c

index 1e14115..31923c7 100755 (executable)
@@ -882,6 +882,7 @@ static void interpret (char *cmd)
                                char num = 0;
                                char input_string[128] = "";
                                char *tok = NULL;
+                               char *ptr = NULL;
                                int tonetime=0;
                                double volume=1.0;
                                int volume_type = -1;
@@ -892,7 +893,7 @@ static void interpret (char *cmd)
                                        fflush(stdin);
                                        g_print("enter number(0~H exit:q), volume type(0~7),  volume(0.0~1.0),  time(ms), enable_session(0:unable , 1:enable):\t ");
                                        if (fgets(input_string, sizeof(input_string)-1, stdin)) {
-                                               tok = strtok(input_string, " ");
+                                               tok = strtok_r(input_string, " ", &ptr);
                                                if(!tok) continue;
                                                if(tok[0] == 'q') {
                                                        break;
@@ -972,13 +973,13 @@ static void interpret (char *cmd)
                                                else if(num == '{')  {  tone =MM_SOUND_TONE_LOW_FRE;    }
                                                else if(num == '}')  {  tone =MM_SOUND_TONE_MED_FRE;    }
                                                else if(num == '~')  {  tone =MM_SOUND_TONE_HIGH_FRE; }
-                                               tok = strtok(NULL, " ");
+                                               tok = strtok_r(NULL, " ", &ptr);
                                                if(tok)  volume_type = (double)atoi(tok);
 
-                                               tok = strtok(NULL, " ");
+                                               tok = strtok_r(NULL, " ", &ptr);
                                                if(tok)  volume = (double)atof(tok);
 
-                                               tok = strtok(NULL, " ");
+                                               tok = strtok_r(NULL, " ", &ptr);
                                                if(tok)
                                                {
                                                        tonetime = atoi(tok);
@@ -988,7 +989,7 @@ static void interpret (char *cmd)
                                                        tonetime = MIN_TONE_PLAY_TIME;
                                                }
 
-                                               tok = strtok(NULL, " ");
+                                               tok = strtok_r(NULL, " ", &ptr);
                                                if(tok)  enable_session = (bool)atof(tok);
 
                                                debug_log("volume type: %d\t volume is %f\t tonetime: %d\t enable_session %d ", volume_type, volume, tonetime, enable_session);
@@ -1005,6 +1006,7 @@ static void interpret (char *cmd)
                                char num = 0;
                                char input_string[128] = "";
                                char *tok = NULL;
+                               char *ptr = NULL;
                                char *stream_type = NULL;
                                int tonetime=0;
                                double volume=1.0;
@@ -1014,7 +1016,7 @@ static void interpret (char *cmd)
                                        fflush(stdin);
                                        g_print("enter number(0~H exit:q), stream type(media, system, ...),  volume(0.0~1.0),  time(ms):\t ");
                                        if (fgets(input_string, sizeof(input_string)-1, stdin)) {
-                                               tok = strtok(input_string, " ");
+                                               tok = strtok_r(input_string, " ", &ptr);
                                                if(!tok) continue;
                                                if(tok[0] == 'q') {
                                                        break;
@@ -1095,12 +1097,12 @@ static void interpret (char *cmd)
                                                else if(num == '}')  {  tone =MM_SOUND_TONE_MED_FRE;    }
                                                else if(num == '~')  {  tone =MM_SOUND_TONE_HIGH_FRE; }
 
-                                               stream_type = strtok(NULL, " ");
+                                               stream_type = strtok_r(NULL, " ", &ptr);
 
-                                               tok = strtok(NULL, " ");
+                                               tok = strtok_r(NULL, " ", &ptr);
                                                if(tok)  volume = (double)atof(tok);
 
-                                               tok = strtok(NULL, " ");
+                                               tok = strtok_r(NULL, " ", &ptr);
                                                if(tok)
                                                {
                                                        tonetime = atoi(tok);
@@ -1122,7 +1124,10 @@ static void interpret (char *cmd)
                        else if (strncmp (cmd, "b",1) == 0)
                        {
                                DIR     *basedir;
-                               struct dirent *entry;
+                               struct dirent *entry = NULL;
+                               struct dirent *prev_entry = NULL;
+                               int entry_len;
+                               int ret;
                                struct stat file_stat;
                                char fullpath[MAX_PATH_LEN]="";
                                struct timespec start_time = {0,};
@@ -1134,10 +1139,23 @@ static void interpret (char *cmd)
                                basedir = opendir(g_dir_name);
                                if(basedir != NULL)
                                {
-                                       while( (entry = readdir(basedir)) != NULL)
+                                       entry_len = offsetof(struct dirent, d_name) + fpathconf(dirfd(basedir), MAX_STRING_LEN) + 1;
+                                       prev_entry = malloc(entry_len);
+
+                                       while (1)
                                        {
-                                               int playfail =0;
+                                               int playfail = 0;
                                                int mywait = 0;
+
+                                               ret = readdir_r(basedir, prev_entry, &entry);
+                                               if (ret == 0)
+                                               {
+                                                       debug_error("error on readdir_r(%s)", basedir);
+                                                       break;
+                                               }
+                                               if (entry == NULL)
+                                                       break;
+
                                                if(entry->d_name[0] == '.')
                                                        continue;
                                                memset(fullpath, '\0' ,sizeof(fullpath));
@@ -1182,6 +1200,7 @@ static void interpret (char *cmd)
                                                }
                                                debug_log("goto next file");
                                        }
+                                       free(prev_entry);
                                        closedir(basedir);
                                }
                                else