Skip to content
This repository was archived by the owner on Sep 7, 2022. It is now read-only.

Commit 5057dee

Browse files
committed
fix possible vulnerabilitys
1 parent c107fd4 commit 5057dee

File tree

8 files changed

+29
-8
lines changed

8 files changed

+29
-8
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
*.project
55
*.cproject
66
*.settings*
7+
*cmake-build-debug/
78

89
#/Build
910
*/Debug/*
@@ -51,3 +52,5 @@
5152

5253

5354

55+
56+

GDBManipulator/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Copyright (C) 2020 Intel Corporation
22
# SPDX-License-Identifier: Apache-2.0
3-
cmake_minimum_required(VERSION 3.2)
3+
cmake_minimum_required(VERSION 3.16)
44
project(gdbMan)
55
set(CMAKE_CXX_STANDARD 11)
66

@@ -16,7 +16,7 @@ include_directories(lib/SimpleLogging/include)
1616
include_directories(src)
1717

1818
message(${src_files})
19-
add_executable(gdbMan ${src_files} src/main.cpp src/main.h )
19+
add_executable(gdbMan src/main.cpp src/main.h ${src_files} )
2020

2121
#link libs
2222
target_link_libraries(gdbMan pthread SimpleLoggingLib CPPArgvParsLib)

GDBManipulator/src/Utils.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ void utils::sharedMemoryInit() {
212212

213213
void utils::sharedMemoryWrite(char *buff, int size) {
214214
#ifdef __linux__
215-
memcpy(shmem, buff, size);
215+
memcpy_s(shmem,128, buff, size);
216216
#elif __WIN32
217217
HANDLE hMapFile;
218218
LPCTSTR pBuf;

GDBManipulator/src/comChain/decoder/GdbClient.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,11 @@ gdbClient::gdbClient(gdbDecoder *decoder_) {
1414

1515
gdbClient::~gdbClient() {
1616
delete decode;
17+
decode = nullptr;
1718
delete errorStream;
19+
errorStream = nullptr;
1820
delete outStream;
21+
outStream = nullptr;
1922

2023
}
2124

GDBManipulator/src/comChain/decoder/GdbInterface.cpp

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,12 @@ char * coppyString(const char * toCoppy)
2424
{
2525
int size = strlen(toCoppy)+1;
2626
char * out = static_cast<char *>(malloc(size));
27+
if(out == 0){
28+
Log::log_("failed to alloc memory",Error);
29+
return 0;
30+
}
2731
memset(out,0,size);
28-
memcpy(out,toCoppy,size);
32+
memcpy_s(out,size,toCoppy,size);
2933
return out;
3034
}
3135

@@ -42,6 +46,10 @@ char ** buildArgv(string applicationCallString, int amountOfAdditionalArguments,
4246
outSize += count(applicationCallString.begin() ,applicationCallString.end(),' ' );
4347
outSize += amountOfAdditionalArguments;
4448
char ** out = static_cast<char**> (malloc(outSize * sizeof(char*)));
49+
if(out == 0){
50+
Log::log_("failed to alloc memory",Error);
51+
return 0;
52+
}
4553
memset(out,0,outSize * sizeof(char*));
4654
int indexInOut = 0;
4755
int subIndex = 0;
@@ -110,7 +118,7 @@ static void handleGDB(string command, nameLessPipe *nlp, string elfLoc, int port
110118
char mi2[] = "--interpreter=mi2";
111119
char qiet[] = "-q";
112120
char port_v[20];
113-
sprintf(port_v, "%d", port);
121+
sprintf_s(port_v,20, "%d", port);
114122

115123
char elf_[elfLoc.length() + 1] = {0,};
116124

@@ -121,6 +129,10 @@ static void handleGDB(string command, nameLessPipe *nlp, string elfLoc, int port
121129
char ** argv = buildArgv(command,4,argsUserDef);
122130
string call = "";
123131
int i = 0;
132+
if(argv == NULL){
133+
Log::log("failed to buildArgv",Error);
134+
return;
135+
}
124136
while(argv[i] != NULL) {
125137
call += string(argv[i]) + " ";
126138
i++;
@@ -203,7 +215,7 @@ static void handleServer(nameLessPipe *nlp) {
203215
notJetFailed = false;
204216
} else if (l.find("Shutting down...") != string::npos) {
205217
char buff[50] = {0,};
206-
sprintf(buff, "%s", utils::sharedMemoryRead());
218+
sprintf_s(buff, "%s",50, utils::sharedMemoryRead());
207219
buff[4] = 0; // set end string if match
208220
if(strcmp(buff,"true") != 0){
209221
Log::log("GDB-Server has been shutting down unexpected", Error, logFilter::GDB_Server);
@@ -238,14 +250,14 @@ static void callGdbServer(string command, nameLessPipe *nlp) {
238250
index = 0;
239251
string location = command.substr(0, index);
240252
Log::log("GDB-Server : set location of child process to " + location, Info, logFilter::GDB_Server);
241-
if(chdir(location.c_str())<0){
253+
if(location == nullpntr || chdir(location.c_str())<0){
242254
return ;
243255
}
244256
if(execv(argv[0], argv) == -1) {
245257
Log::log("GDB-Server exit with errno: \t\"" + string(strerror(errno))+ "\" ", CriticError, logFilter::GDB_Server);
246258
}
247259
char buff[50] = {0,};
248-
sprintf(buff, "%s", utils::sharedMemoryRead());
260+
sprintf_s(buff, "%s",,50, utils::sharedMemoryRead());
249261
buff[4] = 0; // set end string if match
250262
if(strcmp(buff,"true") != 0){
251263
//cout << buff<<endl;

GDBManipulator/src/comChain/decoder/GdbInterface.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ class gdbInterface {
4040

4141
~gdbInterface() {
4242
delete client;
43+
client = nullptr;
4344
}
4445

4546
gdbClient *getClient();;

GDBManipulator/src/eUnitVersionsChecker.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,5 @@ bool defineEunitVersions(){
2020
return false;
2121
if(eUnitFeatureChecker->addFeature(printOverGDB) == FeatureAlreadyExists)
2222
return false;
23+
return true;
2324
}

GDBManipulator/src/tester/MemoryDump.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ uint8_t *memoryDump::getDump() {
6262
memoryDump::~memoryDump() {
6363

6464
delete[] data;
65+
data = nullptr;
6566
}
6667

6768
int memoryDump::getSize() {

0 commit comments

Comments
 (0)