Merge "Fix security issue" into tizen accepted/tizen/4.0/unified/20170816.010946 accepted/tizen/4.0/unified/20170816.014530 accepted/tizen/unified/20170802.151613 submit/tizen/20170802.052926 submit/tizen_4.0/20170811.094300 submit/tizen_4.0/20170814.115522 submit/tizen_4.0_unified/20170814.115522
authorSooyeon Kim <sooyeon.kim@samsung.com>
Mon, 31 Jul 2017 07:19:50 +0000 (07:19 +0000)
committerGerrit Code Review <gerrit@review.ap-northeast-2.compute.internal>
Mon, 31 Jul 2017 07:19:50 +0000 (07:19 +0000)
1  2 
server/sttd_recorder.c

diff --combined server/sttd_recorder.c
@@@ -558,11 -558,27 +558,27 @@@ int sttd_recorder_start(int uid
  #ifdef BUF_SAVE_MODE
        g_count++;
  
-       snprintf(g_temp_file_name, sizeof(g_temp_file_name), "/tmp/stt_temp_%d_%d", getpid(), g_count);
+       while (1) {
+               snprintf(g_temp_file_name, sizeof(g_temp_file_name), "/tmp/stt_temp_%d_%d", getpid(), g_count);
+               ret = access(g_temp_file_name, 0);
+               if (0 == ret) {
+                       SLOG(LOG_ERROR, TAG_STTD, "[Recorder ERROR] File is already exist");
+                       if (0 == remove(g_temp_file_name)) {
+                               SLOG(LOG_DEBUG, TAG_STTD, "[Recorder] Remove file");
+                               break;
+                       } else {
+                               g_count++;
+                       }
+               } else {
+                       break;
+               }
+       }
        SECURE_SLOG(LOG_DEBUG, TAG_STTD, "[Recorder] Temp file name=[%s]", g_temp_file_name);
  
        /* open test file */
-       g_pFile = fopen(g_temp_file_name, "wb+");
+       g_pFile = fopen(g_temp_file_name, "wb+x");
        if (!g_pFile) {
                SLOG(LOG_ERROR, TAG_STTD, "[Recorder ERROR] File not found!");
                return -1;
@@@ -623,70 -639,3 +639,70 @@@ int sttd_recorder_stop(
  
        return 0;
  }
 +
 +int sttd_recorder_start_file(int uid, const char *filepath)
 +{
 +      if (STTD_RECORDER_STATE_RECORDING == g_recorder_state)
 +              return 0;
 +
 +      /* Check engine id is valid */
 +      if (NULL == g_recorder) {
 +              SLOG(LOG_WARN, TAG_STTD, "[Recorder WARNING] Engine id is not valid");
 +              return STTD_ERROR_INVALID_PARAMETER;
 +      }
 +      g_recorder_state = STTD_RECORDER_STATE_RECORDING;
 +      g_recorder->uid = uid;
 +
 +      int cnt = 0;
 +      int totalReadBytes = 0;
 +
 +      FILE *infile = fopen(filepath, "rb");
 +
 +      //process the file
 +      if (infile != NULL) {
 +              while (!feof(infile)) {
 +                      static char pcm_buff[BUFFER_LENGTH];
 +                      int read_byte = fread(pcm_buff, 1, BUFFER_LENGTH, infile);
 +                      totalReadBytes += read_byte;
 +                      if (0 != read_byte) {
 +                              if (0 != g_audio_cb(pcm_buff, read_byte)) {
 +                                      SLOG(LOG_ERROR, TAG_STTD, "[Recorder ERROR] Fail to call audio callback");
 +                                      fclose(infile);
 +                                      return -1;
 +                              }
 +                              if (0 == cnt % 30) {
 +                                      float vol_db = get_volume_decibel(pcm_buff, BUFFER_LENGTH, g_recorder->audio_type);
 +                                      if (0 != sttdc_send_set_volume(g_recorder->uid, vol_db)) {
 +                                              SLOG(LOG_ERROR, TAG_STTD, "[Recorder] Fail to send recording volume(%f)", vol_db);
 +                                      }
 +                              }
 +
 +                              /* Audio read log */
 +                              if (0 == cnt % 50)
 +                                      SLOG(LOG_DEBUG, TAG_STTD, "[Recorder][%d] Recording... : read_size(%d)", cnt, read_byte);
 +                              cnt++;
 +                      }
 +              }
 +              fclose(infile);
 +      }
 +
 +      SLOG(LOG_DEBUG, TAG_STTD, "[Recorder][%d] total bytes(%d)", cnt, totalReadBytes);
 +      return 0;
 +}
 +
 +int sttd_recorder_stop_file()
 +{
 +      if (STTD_RECORDER_STATE_READY == g_recorder_state)
 +              return 0;
 +
 +      /* Check engine id is valid */
 +      if (NULL == g_recorder) {
 +              SLOG(LOG_WARN, TAG_STTD, "[Recorder WARNING] Engine id is not valid");
 +              return STTD_ERROR_INVALID_PARAMETER;
 +      }
 +
 +      g_recorder->uid = -1;
 +      g_recorder_state = STTD_RECORDER_STATE_READY;
 +
 +      return 0;
 +}