Skip to content

Commit 31f61e7

Browse files
committed
Allow long home paths in token store
1 parent 8548965 commit 31f61e7

1 file changed

Lines changed: 12 additions & 2 deletions

File tree

src/internal.c

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1064,7 +1064,11 @@ static int wolfPKCS11_Store_Name(int type, CK_ULONG id1, CK_ULONG id2, char* nam
10641064
#ifndef WOLFPKCS11_NO_ENV
10651065
const char* str = NULL;
10661066
#endif
1067-
char homePath[47]; /* Must fit within name buffer size limit */
1067+
/* Reserve enough space in the final filename for suffixes such as
1068+
* "/wp11_rsakey_priv_%016lx_%016lx" (47 chars worst-case).
1069+
*/
1070+
enum { WP11_STORE_SUFFIX_RESERVE = 48 };
1071+
char homePath[256];
10681072

10691073
/* Path order:
10701074
* 1. Environment variable WOLFPKCS11_TOKEN_PATH
@@ -1125,7 +1129,13 @@ static int wolfPKCS11_Store_Name(int type, CK_ULONG id1, CK_ULONG id2, char* nam
11251129
#endif
11261130

11271131
/* 47 is maximum number of character to a filename and path separator. */
1128-
if (str == NULL || (XSTRLEN(str) > nameLen - sizeof(homePath))) {
1132+
if (str == NULL) {
1133+
return -1;
1134+
}
1135+
if (nameLen <= WP11_STORE_SUFFIX_RESERVE) {
1136+
return -1;
1137+
}
1138+
if (XSTRLEN(str) > (size_t)(nameLen - WP11_STORE_SUFFIX_RESERVE - 1)) {
11291139
return -1;
11301140
}
11311141

0 commit comments

Comments
 (0)