Fix the size of app id
[platform/core/uifw/stt.git] / client / stt.c
index 178f26c..df9091c 100644 (file)
@@ -100,15 +100,15 @@ static bool __check_privilege(const char* uid, const char * privilege)
        char smack_label[1024] = {'\0',};
 
        if (!p_cynara) {
-           return false;
+               return false;
        }
 
        fp = fopen(label_path, "r");
        if (fp != NULL) {
-           if (fread(smack_label, 1, sizeof(smack_label), fp) <= 0)
-               SLOG(LOG_ERROR, TAG_STTC, "[ERROR] fail to fread");
+               if (sizeof(smack_label) != fread(smack_label, 1, sizeof(smack_label), fp))
+                       SLOG(LOG_ERROR, TAG_STTC, "[ERROR] fail to fread");
 
-           fclose(fp);
+               fclose(fp);
        }
 
        pid_t pid = getpid();
@@ -121,7 +121,7 @@ static bool __check_privilege(const char* uid, const char * privilege)
        }
 
        if (ret != CYNARA_API_ACCESS_ALLOWED)
-           return false;
+               return false;
        return true;
 }
 
@@ -1617,8 +1617,8 @@ int stt_start(stt_h stt, const char* language, const char* type)
        }
 
        int ret = -1;
-       char appid[128] = {0, };
-       ret = aul_app_get_appid_bypid(getpid(), appid, sizeof(appid));
+       char appid[1024] = {0, };
+       ret = aul_app_get_appid_bypid(getpid(), appid, sizeof(appid) - 1);
 
        if ((AUL_R_OK != ret) || (0 == strlen(appid))) {
                SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to get application ID");
@@ -1633,8 +1633,15 @@ int stt_start(stt_h stt, const char* language, const char* type)
                temp = strdup(language);
        }
 
+       if (NULL == temp) {
+               SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to allocate memory");
+               return STT_ERROR_OUT_OF_MEMORY;
+       }
+
        if (true == client->credential_needed && NULL == client->credential) {
                SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Do not have app credential for this engine(%s)", client->current_engine_id);
+               free(temp);
+               temp = NULL;
                return STT_ERROR_PERMISSION_DENIED;
        }
 
@@ -1647,7 +1654,8 @@ int stt_start(stt_h stt, const char* language, const char* type)
                SLOG(LOG_DEBUG, TAG_STTC, "[SUCCESS] Start is successful but not done");
        }
 
-       if (NULL != temp)       free(temp);
+       free(temp);
+       temp = NULL;
 
        SLOG(LOG_DEBUG, TAG_STTC, "=====");
        SLOG(LOG_DEBUG, TAG_STTC, " ");
@@ -2086,12 +2094,12 @@ int __stt_cb_result(int uid, int event, char** data, int data_count, const char*
        }
 
        if (NULL != msg)
-               SLOG(LOG_DEBUG, TAG_STTC, "Recognition Result Message = %s", msg);
+               SECURE_SLOG(LOG_DEBUG, TAG_STTC, "Recognition Result Message = %s", msg);
 
        int i = 0;
        for (i = 0; i < data_count; i++) {
                if (NULL != data[i])
-                       SLOG(LOG_DEBUG, TAG_STTC, "Recognition Result[%d] = %s", i, data[i]);
+                       SECURE_SLOG(LOG_DEBUG, TAG_STTC, "Recognition Result[%d] = %s", i, data[i]);
        }
 
        if (NULL != client->recognition_result_cb) {
@@ -2527,8 +2535,8 @@ int stt_start_file(stt_h stt, const char* language, const char* type, const char
        }
 
        int ret = -1;
-       char appid[128] = {0, };
-       ret = aul_app_get_appid_bypid(getpid(), appid, sizeof(appid));
+       char appid[1024] = {0, };
+       ret = aul_app_get_appid_bypid(getpid(), appid, sizeof(appid) - 1);
 
        if ((AUL_R_OK != ret) || (0 == strlen(appid))) {
                SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to get application ID");
@@ -2543,8 +2551,15 @@ int stt_start_file(stt_h stt, const char* language, const char* type, const char
                temp = strdup(language);
        }
 
+       if (NULL == temp) {
+               SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to allocate memory");
+               return STT_ERROR_OUT_OF_MEMORY;
+       }
+
        if (true == client->credential_needed && NULL == client->credential) {
                SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Do not have app credential for this engine(%s)", client->current_engine_id);
+               free(temp);
+               temp = NULL;
                return STT_ERROR_PERMISSION_DENIED;
        }
 
@@ -2557,7 +2572,8 @@ int stt_start_file(stt_h stt, const char* language, const char* type, const char
                SLOG(LOG_DEBUG, TAG_STTC, "[SUCCESS] Start is successful but not done");
        }
 
-       if (NULL != temp)       free(temp);
+       free(temp);
+       temp = NULL;
 
        SLOG(LOG_DEBUG, TAG_STTC, "=====");
        SLOG(LOG_DEBUG, TAG_STTC, " ");