/*
- * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
+ * Copyright (c) 2016-2019 Samsung Electronics Co., Ltd. All rights reserved
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
(void) user_data; // TODO: use UNUSED macro
char file_path_buff[MAX_PATH_LEN] = {0, };
- if (snprintf(file_path_buff, sizeof(file_path_buff), "%s/%s", path, entry->d_name) < 0)
+ if ((unsigned)snprintf(file_path_buff, sizeof(file_path_buff), "%s/%s",
+ path, entry->d_name) >= sizeof(file_path_buff))
return WAE_ERROR_INVALID_PARAMETER; /* buffer size too small */
int ret = WAE_ERROR_NONE;
int _get_preloaded_app_dek_file_path(const char *pkg_id, size_t size, char *path)
{
- if (snprintf(path, size, "%s/%s_%s.adek",
- _get_dek_store_path(), APP_DEK_FILE_PFX, pkg_id) < 0)
+ if ((unsigned)snprintf(path, size, "%s/%s_%s.adek",
+ _get_dek_store_path(), APP_DEK_FILE_PFX, pkg_id) >= size)
return WAE_ERROR_INVALID_PARAMETER; /* buffer size too small */
else
return WAE_ERROR_NONE;
return WAE_ERROR_FILE;
}
+ if (end - start >= MAX_PKGID_LEN) {
+ WAE_SLOGE("WAE: pkgid extracted from APP_DEK file too long. file_name=%s", file_name);
+ return WAE_ERROR_INVALID_PARAMETER;
+ }
+
strncpy(pkg_id, start, end - start);
pkg_id[end - start] = 0; //terminate string
const char *pri_key_path = _get_dek_kek_pri_key_path();
char file_path_buff[MAX_PATH_LEN] = {0, };
- if (snprintf(file_path_buff, sizeof(file_path_buff), "%s/%s", path, entry->d_name) < 0)
+ if ((unsigned)snprintf(file_path_buff, sizeof(file_path_buff), "%s/%s", path, entry->d_name) >= sizeof(file_path_buff))
return WAE_ERROR_INVALID_PARAMETER; /* buffer size too small */
if (strcmp(file_path_buff, pub_key_path) == 0 ||
return ret;
}
-static void _get_alias(const char *name, UNUSED wae_app_type_e type, UNUSED bool forSave,
+static int _get_alias(const char *name, UNUSED wae_app_type_e type, UNUSED bool forSave,
char *alias, size_t buff_len)
{
- snprintf(alias, buff_len, "%s%s%s%s",
+ if ((unsigned)snprintf(alias, buff_len, "%s%s%s%s",
ckmc_owner_id_system,
ckmc_owner_id_separator,
APP_DEK_ALIAS_PFX,
- name);
+ name) >= buff_len) {
+ WAE_SLOGE("Alias buffer too small for name(%s)", name);
+ return WAE_ERROR_INVALID_PARAMETER;
+ }
+ return WAE_ERROR_NONE;
}
int save_to_key_manager(const char *name, const char *pkg_id, wae_app_type_e type,
{
char alias[MAX_ALIAS_LEN] = {0, };
- _get_alias(name, type, true, alias, sizeof(alias));
+ int ret = _get_alias(name, type, true, alias, sizeof(alias));
+ if (ret != WAE_ERROR_NONE)
+ return ret;
ckmc_raw_buffer_s *buf = NULL;
- int ret = _serialize(ce, &buf);
+ ret = _serialize(ce, &buf);
if (ret != WAE_ERROR_NONE) {
WAE_SLOGE("Failed to serialize crypto element of name(%s)", name);
return ret;
char alias[MAX_ALIAS_LEN] = {0, };
- _get_alias(name, type, false, alias, sizeof(alias));
+ int ret = _get_alias(name, type, false, alias, sizeof(alias));
+ if (ret != WAE_ERROR_NONE)
+ return ret;
ckmc_raw_buffer_s *buf = NULL;
- int ret = _to_wae_error(ckmc_get_data(alias, NULL, &buf));
+ ret = _to_wae_error(ckmc_get_data(alias, NULL, &buf));
if (ret != WAE_ERROR_NONE)
return ret;
{
char alias[MAX_ALIAS_LEN] = {0, };
- _get_alias(name, type, true, alias, sizeof(alias));
+ int ret = _get_alias(name, type, true, alias, sizeof(alias));
+ if (ret != WAE_ERROR_NONE)
+ return ret;
return _to_wae_error(ckmc_remove_alias(alias));
}
-static void _get_dek_kek_alias(char *alias, size_t buff_len)
+static int _get_dek_kek_alias(char *alias, size_t buff_len)
{
- snprintf(alias, buff_len, "%s%s%s",
+ return (unsigned)snprintf(alias, buff_len, "%s%s%s",
ckmc_owner_id_system,
ckmc_owner_id_separator,
- APP_DEK_KEK_ALIAS);
+ APP_DEK_KEK_ALIAS) >= buff_len
+ ? WAE_ERROR_INVALID_PARAMETER
+ : WAE_ERROR_NONE;
}
int get_dek_kek_from_key_manager(raw_buffer_s **pdek_kek)
ckmc_raw_buffer_s *buf = NULL;
char alias[MAX_ALIAS_LEN] = {0, };
- _get_dek_kek_alias(alias, sizeof(alias));
+ int ret = _get_dek_kek_alias(alias, sizeof(alias));
+ if (ret != WAE_ERROR_NONE)
+ return ret;
- int ret = _to_wae_error(ckmc_get_data(alias, NULL, &buf));
+ ret = _to_wae_error(ckmc_get_data(alias, NULL, &buf));
if (ret != WAE_ERROR_NONE) {
WAE_SLOGE("Failed to get dek kek from key-manager. alias(%s) ret(%d)",
alias, ret);