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

Merge PR #661: resolve several coverity issues

This commit is contained in:
Davide Beatrici 2018-08-21 10:21:57 +02:00 committed by GitHub
commit dbd4b9e7c2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 8 additions and 135 deletions

View File

@ -2664,7 +2664,7 @@ void EthPutPacketLinuxIpRaw(ETH *e, void *data, UINT size)
p = ParsePacket(data, size); p = ParsePacket(data, size);
if (p && p->BroadcastPacket || Cmp(p->MacAddressDest, e->RawIpMyMacAddr, 6) == 0) if (p != NULL && p->BroadcastPacket || Cmp(p->MacAddressDest, e->RawIpMyMacAddr, 6) == 0)
{ {
if (IsValidUnicastMacAddress(p->MacAddressSrc)) if (IsValidUnicastMacAddress(p->MacAddressSrc))
{ {

View File

@ -5645,7 +5645,7 @@ void ClientUploadNoop(CONNECTION *c)
p = PackError(0); p = PackError(0);
PackAddInt(p, "noop", 1); PackAddInt(p, "noop", 1);
HttpClientSend(c->FirstSock, p); (void)HttpClientSend(c->FirstSock, p);
FreePack(p); FreePack(p);
p = HttpClientRecv(c->FirstSock); p = HttpClientRecv(c->FirstSock);
@ -5942,15 +5942,12 @@ bool ServerDownloadSignature(CONNECTION *c, char **error_detail_str)
UINT num = 0, max = 19; UINT num = 0, max = 19;
SERVER *server; SERVER *server;
char *vpn_http_target = HTTP_VPN_TARGET2; char *vpn_http_target = HTTP_VPN_TARGET2;
bool check_hostname = false;
// Validate arguments // Validate arguments
if (c == NULL) if (c == NULL)
{ {
return false; return false;
} }
server = c->Cedar->Server; server = c->Cedar->Server;
s = c->FirstSock; s = c->FirstSock;
@ -5977,33 +5974,6 @@ bool ServerDownloadSignature(CONNECTION *c, char **error_detail_str)
return false; return false;
} }
if (check_hostname && (StrCmpi(h->Version, "HTTP/1.1") == 0 || StrCmpi(h->Version, "HTTP/1.2") == 0))
{
HTTP_VALUE *v;
char hostname[64];
Zero(hostname, sizeof(hostname));
v = GetHttpValue(h, "Host");
if (v != NULL)
{
StrCpy(hostname, sizeof(hostname), v->Data);
}
if (IsEmptyStr(hostname))
{
// Invalid hostname
HttpSendInvalidHostname(s, h->Target);
FreeHttpHeader(h);
c->Err = ERR_CLIENT_IS_NOT_VPN;
*error_detail_str = "Invalid_hostname";
return false;
}
}
// Interpret // Interpret
if (StrCmpi(h->Method, "POST") == 0) if (StrCmpi(h->Method, "POST") == 0)
{ {

View File

@ -1072,9 +1072,9 @@ void NnFragmentedIpReceived(NATIVE_NAT *t, PKT *packet)
c = NnInsertIpCombine( c = NnInsertIpCombine(
t, ip->SrcIP, ip->DstIP, Endian16(ip->Identification), ip->Protocol, packet->BroadcastPacket, t, ip->SrcIP, ip->DstIP, Endian16(ip->Identification), ip->Protocol, packet->BroadcastPacket,
ip->TimeToLive, false); ip->TimeToLive, false);
c->MaxL3Size = MAX(c->MaxL3Size, l3_size);
if (c != NULL) if (c != NULL)
{ {
c->MaxL3Size = MAX(c->MaxL3Size, l3_size);
NnCombineIp(t, c, offset, data, size, last_packet, head_ip_header_data, head_ip_header_size); NnCombineIp(t, c, offset, data, size, last_packet, head_ip_header_data, head_ip_header_size);
} }
} }

View File

@ -178,7 +178,7 @@ int local_scandir(const char *dir, struct dirent ***namelist,
*namelist=NULL; *namelist=NULL;
while ((entry=readdir(d)) != NULL) while ((entry=readdir(d)) != NULL)
{ {
if (select == NULL || (select != NULL && (*select)(entry))) if (select == NULL || (*select)(entry))
{ {
*namelist=(struct dirent **)realloc((void *)(*namelist), *namelist=(struct dirent **)realloc((void *)(*namelist),
(size_t)((i+1)*sizeof(struct dirent *))); (size_t)((i+1)*sizeof(struct dirent *)));
@ -516,7 +516,7 @@ void UnixInitSolarisSleep()
char tmp[MAX_SIZE]; char tmp[MAX_SIZE];
UnixNewPipe(&solaris_sleep_p1, &solaris_sleep_p2); UnixNewPipe(&solaris_sleep_p1, &solaris_sleep_p2);
read(solaris_sleep_p1, tmp, sizeof(tmp)); (void)read(solaris_sleep_p1, tmp, sizeof(tmp));
} }
// Release the Sleep for Solaris // Release the Sleep for Solaris
@ -540,17 +540,6 @@ void UnixSolarisSleep(UINT msec)
} }
// Get the free space of the disk // Get the free space of the disk
bool UnixGetDiskFreeW(wchar_t *path, UINT64 *free_size, UINT64 *used_size, UINT64 *total_size)
{
char *path_a = CopyUniToStr(path);
bool ret;
ret = UnixGetDiskFree(path_a, free_size, used_size, total_size);
Free(path_a);
return ret;
}
bool UnixGetDiskFree(char *path, UINT64 *free_size, UINT64 *used_size, UINT64 *total_size) bool UnixGetDiskFree(char *path, UINT64 *free_size, UINT64 *used_size, UINT64 *total_size)
{ {
char tmp[MAX_PATH]; char tmp[MAX_PATH];
@ -803,42 +792,6 @@ void UnixSetThreadPriorityRealtime()
pthread_setschedparam(pthread_self(), SCHED_RR, &p); pthread_setschedparam(pthread_self(), SCHED_RR, &p);
} }
// Lower the priority of the thread
void UnixSetThreadPriorityLow()
{
struct sched_param p;
Zero(&p, sizeof(p));
p.sched_priority = 32;
pthread_setschedparam(pthread_self(), SCHED_OTHER, &p);
}
// Raise the priority of the thread
void UnixSetThreadPriorityHigh()
{
struct sched_param p;
Zero(&p, sizeof(p));
p.sched_priority = 127;
pthread_setschedparam(pthread_self(), SCHED_RR, &p);
}
// Set the priority of the thread to idle
void UnixSetThreadPriorityIdle()
{
struct sched_param p;
Zero(&p, sizeof(p));
p.sched_priority = 1;
pthread_setschedparam(pthread_self(), SCHED_OTHER, &p);
}
// Restore the priority of the thread to normal
void UnixRestoreThreadPriority()
{
struct sched_param p;
Zero(&p, sizeof(p));
p.sched_priority = 64;
pthread_setschedparam(pthread_self(), SCHED_OTHER, &p);
}
// Get the current directory // Get the current directory
void UnixGetCurrentDir(char *dir, UINT size) void UnixGetCurrentDir(char *dir, UINT size)
{ {
@ -899,7 +852,7 @@ void UnixFreeSingleInstance(void *data)
lock.l_type = F_UNLCK; lock.l_type = F_UNLCK;
lock.l_whence = SEEK_SET; lock.l_whence = SEEK_SET;
fcntl(o->fd, F_SETLK, &lock); (void)fcntl(o->fd, F_SETLK, &lock);
close(o->fd); close(o->fd);
remove(o->FileName); remove(o->FileName);
@ -947,7 +900,7 @@ void *UnixNewSingleInstance(char *instance_name)
} }
fchmod(fd, mode); fchmod(fd, mode);
chmod(name, mode); (void)chmod(name, mode);
Zero(&lock, sizeof(lock)); Zero(&lock, sizeof(lock));
lock.l_type = F_WRLCK; lock.l_type = F_WRLCK;
@ -1293,43 +1246,6 @@ bool UnixRun(char *filename, char *arg, bool hide, bool wait)
} }
} }
// Initialize the daemon
void UnixDaemon(bool debug_mode)
{
UINT ret;
if (debug_mode)
{
// Debug mode
signal(SIGHUP, SIG_IGN);
return;
}
ret = fork();
if (ret == -1)
{
// Error
return;
}
else if (ret == 0)
{
// Create a new session for the child process
setsid();
// Close the standard I/O
UnixCloseIO();
// Mute the unwanted signal
signal(SIGHUP, SIG_IGN);
}
else
{
// Terminate the parent process
exit(0);
}
}
// Close the standard I/O // Close the standard I/O
void UnixCloseIO() void UnixCloseIO()
{ {
@ -1826,7 +1742,7 @@ bool UnixInitThread(THREAD *t)
{ {
// An error has occured // An error has occured
t->pData = NULL; t->pData = NULL;
Release(t->ref); (void)Release(t->ref);
UnixMemoryFree(ut); UnixMemoryFree(ut);
UnixMemoryFree(info); UnixMemoryFree(info);
pthread_attr_destroy(&attr); pthread_attr_destroy(&attr);
@ -2640,8 +2556,6 @@ void UnixStopService(char *name)
} }
else else
{ {
int status;
// Stop the service // Stop the service
UniPrint(_UU("UNIX_SVC_STOPPING"), svc_title); UniPrint(_UU("UNIX_SVC_STOPPING"), svc_title);
@ -2802,10 +2716,6 @@ bool UnixWaitProcessEx(UINT pid, UINT timeout)
} }
return true; return true;
} }
void UnixWaitProcess(UINT pid)
{
UnixWaitProcessEx(pid, INFINITE);
}
// Description of how to start // Description of how to start
void UnixUsage(char *name) void UnixUsage(char *name)

View File

@ -218,16 +218,11 @@ void UnixSetEnableKernelEspProcessing(bool b);
void UnixDisableCoreDump(); void UnixDisableCoreDump();
void UnixSetThreadPriorityRealtime(); void UnixSetThreadPriorityRealtime();
void UnixSetThreadPriorityLow();
void UnixSetThreadPriorityHigh();
void UnixSetThreadPriorityIdle();
void UnixRestoreThreadPriority();
void UnixSetResourceLimit(UINT id, UINT64 value); void UnixSetResourceLimit(UINT id, UINT64 value);
bool UnixIs64BitRlimSupported(); bool UnixIs64BitRlimSupported();
UINT64 UnixGetTick64(); UINT64 UnixGetTick64();
void UnixSigChldHandler(int sig); void UnixSigChldHandler(int sig);
void UnixCloseIO(); void UnixCloseIO();
void UnixDaemon(bool debug_mode);
void UnixGetCurrentDir(char *dir, UINT size); void UnixGetCurrentDir(char *dir, UINT size);
void UnixGetCurrentDirW(wchar_t *dir, UINT size); void UnixGetCurrentDirW(wchar_t *dir, UINT size);
bool UnixCheckExecAccess(char *name); bool UnixCheckExecAccess(char *name);
@ -236,7 +231,6 @@ DIRLIST *UnixEnumDirEx(char *dirname, COMPARE *compare);
DIRLIST *UnixEnumDirExW(wchar_t *dirname, COMPARE *compare); DIRLIST *UnixEnumDirExW(wchar_t *dirname, COMPARE *compare);
bool UnixGetDiskFreeMain(char *path, UINT64 *free_size, UINT64 *used_size, UINT64 *total_size); bool UnixGetDiskFreeMain(char *path, UINT64 *free_size, UINT64 *used_size, UINT64 *total_size);
bool UnixGetDiskFree(char *path, UINT64 *free_size, UINT64 *used_size, UINT64 *total_size); bool UnixGetDiskFree(char *path, UINT64 *free_size, UINT64 *used_size, UINT64 *total_size);
bool UnixGetDiskFreeW(wchar_t *path, UINT64 *free_size, UINT64 *used_size, UINT64 *total_size);
void UnixInitSolarisSleep(); void UnixInitSolarisSleep();
void UnixFreeSolarisSleep(); void UnixFreeSolarisSleep();
void UnixSolarisSleep(UINT msec); void UnixSolarisSleep(UINT msec);
@ -255,7 +249,6 @@ UINT UnixReadPidFile();
UINT UnixReadCtlFile(); UINT UnixReadCtlFile();
bool UnixIsProcess(UINT pid); bool UnixIsProcess(UINT pid);
bool UnixWaitProcessEx(UINT pid, UINT timeout); bool UnixWaitProcessEx(UINT pid, UINT timeout);
void UnixWaitProcess(UINT pid);
void UnixDeletePidFile(); void UnixDeletePidFile();
void UnixDeleteCtlFile(); void UnixDeleteCtlFile();
void UnixStopThread(THREAD *t, void *param); void UnixStopThread(THREAD *t, void *param);