diff --git a/tee-supplicant/src/tee_supplicant.c b/tee-supplicant/src/tee_supplicant.c index 4fc247c4..34238c3f 100644 --- a/tee-supplicant/src/tee_supplicant.c +++ b/tee-supplicant/src/tee_supplicant.c @@ -706,6 +706,7 @@ static void set_ta_path(void) char *new_path = NULL; size_t n = 0; const char *path = supplicant_params.ta_load_path; + int path_len = -1; if (!path) path = TEEC_LOAD_PATH; @@ -733,10 +734,17 @@ static void set_ta_path(void) if (!supplicant_params.ta_load_path) { char full_path[PATH_MAX] = { 0 }; - snprintf(full_path, PATH_MAX, "%s/%s", new_path, - supplicant_params.ta_dir); + path_len = snprintf(full_path, PATH_MAX, "%s/%s", new_path, + supplicant_params.ta_dir); + if (path_len < 0 || path_len >= PATH_MAX) + goto err_path; + ta_path[n++] = strdup(full_path); } else { + path_len = strnlen(new_path, PATH_MAX); + if (path_len == PATH_MAX) + goto err_path; + ta_path[n++] = strdup(new_path); } @@ -749,6 +757,10 @@ static void set_ta_path(void) err: EMSG("out of memory"); exit(EXIT_FAILURE); + +err_path: + EMSG("Path exceeds maximum path length"); + exit(EXIT_FAILURE); } /*