Skip to content

Commit 38c2ca6

Browse files
authored
sgx: fix the build warning (#653)
fix the warnings as below: App/App.cpp: In function ‘int wamr_pal_init(const wamr_pal_attr*)’: App/App.cpp:759:1: warning: control reaches end of non-void function [-Wreturn-type] 759 | } | ^ In file included from /usr/include/string.h:495, from App/App.cpp:9: In function ‘char* strncpy(char*, const char*, size_t)’, inlined from ‘int enclave_init(sgx_enclave_id_t*)’ at App/App.cpp:104:16: /usr/include/x86_64-linux-gnu/bits/string_fortified.h:106:34: warning: ‘char* __builtin___strncpy_chk(char*, const char*, long unsigned int, long unsigned int)’ specified bound depends on the length of the source argument [-Wstringop-overflow=] 106 | return __builtin___strncpy_chk (__dest, __src, __len, __bos (__dest)); | ~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ App/App.cpp: In function ‘int enclave_init(sgx_enclave_id_t*)’: App/App.cpp:102:16: note: length computed here 102 | (strlen(home_dir) + strlen("/") + sizeof(TOKEN_FILENAME) + 1) <= MAX_PATH) { | ~~~~~~^~~~~~~~~~ Signed-off-by: LiFeng <[email protected]>
1 parent 77c71e5 commit 38c2ca6

File tree

1 file changed

+4
-2
lines changed
  • product-mini/platforms/linux-sgx/enclave-sample/App

1 file changed

+4
-2
lines changed

product-mini/platforms/linux-sgx/enclave-sample/App/App.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,11 +97,12 @@ enclave_init(sgx_enclave_id_t *p_eid)
9797
*/
9898
/* try to get the token saved in $HOME */
9999
home_dir = getpwuid(getuid())->pw_dir;
100+
size_t home_dir_len = home_dir ? strlen(home_dir) : 0;
100101

101102
if (home_dir != NULL &&
102-
(strlen(home_dir) + strlen("/") + sizeof(TOKEN_FILENAME) + 1) <= MAX_PATH) {
103+
home_dir_len <= MAX_PATH - 1 - sizeof(TOKEN_FILENAME) - strlen("/")) {
103104
/* compose the token path */
104-
strncpy(token_path, home_dir, strlen(home_dir));
105+
strncpy(token_path, home_dir, MAX_PATH);
105106
strncat(token_path, "/", strlen("/"));
106107
strncat(token_path, TOKEN_FILENAME, sizeof(TOKEN_FILENAME) + 1);
107108
}
@@ -756,6 +757,7 @@ wamr_pal_init(const struct wamr_pal_attr *args)
756757
std::cout << "Fail to initialize enclave." << std::endl;
757758
return 1;
758759
}
760+
return 0;
759761
}
760762

761763
int

0 commit comments

Comments
 (0)