1
0
mirror of https://github.com/SoftEtherVPN/SoftEtherVPN.git synced 2024-11-26 11:29:53 +03:00

Merge pull request #724 from dnobori/180928_fixbugs

Merge PR #724: Fix bugs reported by Coverity Scan.
This commit is contained in:
Ilya Shipitsin 2018-09-28 21:41:12 +05:00 committed by GitHub
commit 3110ca530e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 29 additions and 15 deletions

View File

@ -9982,7 +9982,7 @@ char *DecryptPassword(BUF *b)
} }
str = ZeroMalloc(b->Size + 1); str = ZeroMalloc(b->Size + 1);
c = NewCrypt(key, sizeof(key)); c = NewCrypt(key, sizeof(key)); // NOTE by Daiyuu Nobori 2018-09-28: This is not a bug! Do not try to fix it!!
Encrypt(c, str, b->Buf, b->Size); Encrypt(c, str, b->Buf, b->Size);
FreeCrypt(c); FreeCrypt(c);
@ -10028,7 +10028,7 @@ BUF *EncryptPassword(char *password)
size = StrLen(password) + 1; size = StrLen(password) + 1;
tmp = ZeroMalloc(size); tmp = ZeroMalloc(size);
c = NewCrypt(key, sizeof(key)); c = NewCrypt(key, sizeof(key)); // NOTE by Daiyuu Nobori 2018-09-28: This is not a bug! Do not try to fix it!!
Encrypt(c, tmp, password, size - 1); Encrypt(c, tmp, password, size - 1);
FreeCrypt(c); FreeCrypt(c);

View File

@ -1579,7 +1579,7 @@ SEND_START:
{ {
// Packet data array // Packet data array
void **datas = MallocFast(sizeof(void *) * num_packet); void **datas = MallocFast(sizeof(void *) * num_packet);
UINT *sizes = MallocFast(sizeof(UINT *) * num_packet); UINT *sizes = MallocFast(sizeof(UINT) * num_packet);
UINT i; UINT i;
i = 0; i = 0;

View File

@ -3717,10 +3717,13 @@ bool HubPaPutPacket(SESSION *s, void *data, UINT size)
CancelList(s->CancelList); CancelList(s->CancelList);
// Yield // Yield
if (hub != NULL)
{
if (hub->Option != NULL && hub->Option->YieldAfterStorePacket) if (hub->Option != NULL && hub->Option->YieldAfterStorePacket)
{ {
YieldCpu(); YieldCpu();
} }
}
return true; return true;
} }

View File

@ -6011,7 +6011,7 @@ bool ServerDownloadSignature(CONNECTION *c, char **error_detail_str)
{ {
// Compare posted data with the WaterMark // Compare posted data with the WaterMark
if ((data_size == StrLen(HTTP_VPN_TARGET_POSTDATA) && (Cmp(data, HTTP_VPN_TARGET_POSTDATA, data_size) == 0)) if ((data_size == StrLen(HTTP_VPN_TARGET_POSTDATA) && (Cmp(data, HTTP_VPN_TARGET_POSTDATA, data_size) == 0))
|| (Cmp(data, WaterMark, SizeOfWaterMark()) == 0)) || ((data_size >= SizeOfWaterMark()) && Cmp(data, WaterMark, SizeOfWaterMark()) == 0))
{ {
// Check the WaterMark // Check the WaterMark
Free(data); Free(data);

View File

@ -2054,6 +2054,12 @@ UINT SiCalcPoint(SERVER *s, UINT num, UINT weight)
server_max_sessions = GetServerCapsInt(s, "i_max_sessions"); server_max_sessions = GetServerCapsInt(s, "i_max_sessions");
if (server_max_sessions == 0)
{
// Avoid divide by zero
server_max_sessions = 1;
}
return (UINT)(((double)server_max_sessions - return (UINT)(((double)server_max_sessions -
MIN((double)num * 100.0 / (double)weight, (double)server_max_sessions)) MIN((double)num * 100.0 / (double)weight, (double)server_max_sessions))
* (double)FARM_BASE_POINT / (double)server_max_sessions); * (double)FARM_BASE_POINT / (double)server_max_sessions);

View File

@ -5307,7 +5307,7 @@ TCP_RESET:
seq64 = n->RecvSeq + (UINT64)seq - (n->RecvSeqInit + n->RecvSeq) % X32; seq64 = n->RecvSeq + (UINT64)seq - (n->RecvSeqInit + n->RecvSeq) % X32;
if ((n->RecvSeqInit + n->RecvSeq) % X32 > seq) if ((n->RecvSeqInit + n->RecvSeq) % X32 > seq)
{ {
if (((n->RecvSeqInit + n->RecvSeq) % X32 - ack) >= 0x80000000) if (((n->RecvSeqInit + n->RecvSeq) % X32 - seq) >= 0x80000000)
{ {
seq64 = n->RecvSeq + (UINT64)seq + X32 - (n->RecvSeqInit + n->RecvSeq) % X32; seq64 = n->RecvSeq + (UINT64)seq + X32 - (n->RecvSeqInit + n->RecvSeq) % X32;
} }

View File

@ -1222,7 +1222,7 @@ static wchar_t *WpSecureNAT(WEBUI *wu, LIST *params)
// Get the enable / disable state of the current SecureNAT // Get the enable / disable state of the current SecureNAT
{ {
RPC_HUB_STATUS t; RPC_HUB_STATUS t;
Zero(&t, sizeof(&t)); Zero(&t, sizeof(t));
StrCpy(t.HubName, sizeof(t.HubName), hubname); StrCpy(t.HubName, sizeof(t.HubName), hubname);
retcode = StGetHubStatus(context->Admin, &t); retcode = StGetHubStatus(context->Admin, &t);
@ -1649,7 +1649,7 @@ static LIST *WuAnalyzeTarget(char *target,char *filename, UINT size)
while(*body != '=' && *body != '\0') while(*body != '=' && *body != '\0')
{ {
*body ++; body++;
} }
if(*body == '=') if(*body == '=')
{ {

View File

@ -513,7 +513,7 @@ void GetHomeDirW(wchar_t *path, UINT size)
if (GetEnvW(L"HOMEDRIVE", drive, sizeof(drive)) && if (GetEnvW(L"HOMEDRIVE", drive, sizeof(drive)) &&
GetEnvW(L"HOMEPATH", hpath, sizeof(hpath))) GetEnvW(L"HOMEPATH", hpath, sizeof(hpath)))
{ {
UniFormat(path, sizeof(path), L"%s%s", drive, hpath); UniFormat(path, size, L"%s%s", drive, hpath);
} }
else else
{ {

View File

@ -15081,7 +15081,7 @@ void GetMachineNameEx(char *name, UINT size, bool no_load_hosts)
{ {
if (GetMachineNameFromHosts(tmp2, sizeof(tmp2))) if (GetMachineNameFromHosts(tmp2, sizeof(tmp2)))
{ {
StrCpy(name, sizeof(name), tmp2); StrCpy(name, size, tmp2);
} }
} }
} }

View File

@ -1824,7 +1824,7 @@ SECURE *OpenSec(UINT id)
return NULL; return NULL;
} }
sec->SlotIdList = (UINT *)ZeroMalloc(sizeof(UINT *) * sec->NumSlot); sec->SlotIdList = (UINT *)ZeroMalloc(sizeof(UINT) * sec->NumSlot);
if (sec->Api->C_GetSlotList(TRUE, sec->SlotIdList, &sec->NumSlot) != CKR_OK) if (sec->Api->C_GetSlotList(TRUE, sec->SlotIdList, &sec->NumSlot) != CKR_OK)
{ {

View File

@ -999,7 +999,7 @@ BUF *BuildICMPv6NeighborSoliciation(IPV6_ADDR *src_ip, IPV6_ADDR *target_ip, UCH
UCHAR IPv6GetNextHeaderFromQueue(QUEUE *q) UCHAR IPv6GetNextHeaderFromQueue(QUEUE *q)
{ {
UINT *p; UINT *p;
UCHAR v; UCHAR v = 0;
// Validate arguments // Validate arguments
if (q == NULL) if (q == NULL)
{ {
@ -1007,8 +1007,11 @@ UCHAR IPv6GetNextHeaderFromQueue(QUEUE *q)
} }
p = (UINT *)GetNext(q); p = (UINT *)GetNext(q);
if (p != NULL)
{
v = (UCHAR)(*p); v = (UCHAR)(*p);
Free(p); Free(p);
}
return v; return v;
} }

View File

@ -906,6 +906,8 @@ void *UnixNewSingleInstance(char *instance_name)
if (fcntl(fd, F_SETLK, &lock) == -1) if (fcntl(fd, F_SETLK, &lock) == -1)
{ {
close(fd);
(void)remove(name);
return NULL; return NULL;
} }
else else