1
0
mirror of https://github.com/SoftEtherVPN/SoftEtherVPN.git synced 2025-11-25 04:41:33 +03:00

Remove all references to strtok() and wcstok(), implement and use alternatives

strtok() and wcstok() are considered unsafe functions.

A segmentation fault caused by the use of strtok() was recently reported.

Co-authored-by: Takuho NAKANO <takotakot@users.noreply.github.com>
This commit is contained in:
Daiyuu Nobori
2020-07-20 17:53:45 +02:00
committed by Davide Beatrici
parent 3baf4674e7
commit 844dcdb0af
3 changed files with 169 additions and 122 deletions

View File

@ -2379,54 +2379,8 @@ void FreeToken(TOKEN_LIST *tokens)
// Parse the token
TOKEN_LIST *ParseToken(char *src, char *separator)
{
TOKEN_LIST *ret;
char *tmp;
char *str1, *str2;
UINT len;
UINT num;
if (src == NULL)
{
ret = ZeroMalloc(sizeof(TOKEN_LIST));
ret->Token = ZeroMalloc(0);
return ret;
}
if (separator == NULL)
{
separator = " ,\t\r\n";
}
len = StrLen(src);
str1 = Malloc(len + 1);
str2 = Malloc(len + 1);
StrCpy(str1, 0, src);
StrCpy(str2, 0, src);
Lock(token_lock);
{
tmp = strtok(str1, separator);
num = 0;
while (tmp != NULL)
{
num++;
tmp = strtok(NULL, separator);
}
ret = Malloc(sizeof(TOKEN_LIST));
ret->NumTokens = num;
ret->Token = (char **)Malloc(sizeof(char *) * num);
num = 0;
tmp = strtok(str2, separator);
while (tmp != NULL)
{
ret->Token[num] = (char *)Malloc(StrLen(tmp) + 1);
StrCpy(ret->Token[num], 0, tmp);
num++;
tmp = strtok(NULL, separator);
}
}
Unlock(token_lock);
Free(str1);
Free(str2);
return ret;
// 2020/7/20 remove strtok by dnobori
return ParseTokenWithoutNullStr(src, separator);
}
// Get a line from standard input
@ -5136,4 +5090,3 @@ void SystemTime64ToJsonStr(char *dst, UINT size, UINT64 t)