@@ -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;
0 commit comments