summaryrefslogtreecommitdiff
path: root/srcs/key_handler.c
diff options
context:
space:
mode:
authorKonrad Lipinski <k.lipinski2@partner.samsung.com>2019-04-30 09:11:06 +0200
committerKonrad Lipinski <k.lipinski2@partner.samsung.com>2019-05-07 10:40:44 +0200
commit199c7f3bf33675e855ec69a75c60dbffd293c490 (patch)
tree05d454b832588d7581a665cf8b067f2f404c5214 /srcs/key_handler.c
parent14e94dc420fdc4eb2a39f8f06f5320b97cc1d6b7 (diff)
downloadlibwebappenc-199c7f3bf33675e855ec69a75c60dbffd293c490.tar.gz
libwebappenc-199c7f3bf33675e855ec69a75c60dbffd293c490.tar.bz2
libwebappenc-199c7f3bf33675e855ec69a75c60dbffd293c490.zip
Fix c++test defects (snprintf, strncpy usage)
Change-Id: I1e548235272c53be62a304443a4847b98a9b1f90
Diffstat (limited to 'srcs/key_handler.c')
-rw-r--r--srcs/key_handler.c16
1 files changed, 11 insertions, 5 deletions
diff --git a/srcs/key_handler.c b/srcs/key_handler.c
index e095903..a60142e 100644
--- a/srcs/key_handler.c
+++ b/srcs/key_handler.c
@@ -1,5 +1,5 @@
/*
- * 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.
@@ -248,7 +248,8 @@ static int _entry_callback_remove_all(
(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;
@@ -273,8 +274,8 @@ void _remove_directory(const char *path)
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;
@@ -297,6 +298,11 @@ static int _extract_pkg_id_from_file_name(const char *file_name, char *pkg_id)
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
@@ -616,7 +622,7 @@ static int _entry_callback_load_preloaded_adeks(
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 ||