@@ -251,15 +251,18 @@ int W_isRootcheck(cJSON *root, int nested){
251
251
// ** TODO ** Regex instead str_cut
252
252
void W_JSON_ParseHostname (cJSON * root , char * hostname ){
253
253
if (hostname [0 ] == '(' ){
254
- char * e ;
255
- char string [strlen ( hostname ) + 1 ];
256
- strcpy (string ,hostname );
254
+ char * search ;
255
+ char string [MAX_STRING ];
256
+ strncpy (string ,hostname , MAX_STRING - 1 );
257
257
int index ;
258
- e = strchr (string , ')' );
259
- index = (int )(e - string );
260
- str_cut (string , index , -1 );
261
- str_cut (string , 0 , 1 );
262
- cJSON_AddStringToObject (root , "hostname" , string );
258
+ search = strchr (string , ')' );
259
+ if (search ){
260
+ index = (int )(search - string );
261
+ str_cut (string , index , -1 );
262
+ str_cut (string , 0 , 1 );
263
+ cJSON_AddStringToObject (root , "hostname" , string );
264
+ }
265
+
263
266
}else {
264
267
cJSON_AddStringToObject (root , "hostname" , hostname );
265
268
}
@@ -276,36 +279,41 @@ void W_JSON_ParseHostname(cJSON *root, char *hostname){
276
279
// ** TODO ** Regex instead str_cut
277
280
void W_JSON_ParseAgentIP (cJSON * root , const Eventinfo * lf ){
278
281
if (lf -> hostname [0 ] == '(' ){
279
- char * e ;
280
- char string [strlen ( lf -> hostname ) + 1 ];
281
- strcpy (string ,lf -> hostname );
282
+ char * search ;
283
+ char string [MAX_STRING ];
284
+ strncpy (string ,lf -> hostname , MAX_STRING - 1 );
282
285
int index ;
283
- e = strchr (string , ')' );
284
- index = (int )(e - string );
285
- str_cut (string , 0 , index );
286
- str_cut (string , 0 , 2 );
287
- e = strchr (string , '-' );
288
- index = (int )(e - string );
289
- str_cut (string , index , -1 );
290
- cJSON_AddStringToObject (root , "agentip" , string );
286
+ search = strchr (string , ')' );
287
+ if (search ){
288
+ index = (int )(search - string );
289
+ str_cut (string , 0 , index );
290
+ str_cut (string , 0 , 2 );
291
+ search = strchr (string , '-' );
292
+ index = (int )(search - string );
293
+ str_cut (string , index , -1 );
294
+ cJSON_AddStringToObject (root , "agentip" , string );
295
+ }
291
296
}
292
297
293
298
}
294
299
// The file location usually comes with more information about the alert (like hostname or ip) we will extract just the "/var/folder/file.log".
295
300
void W_JSON_ParseLocation (cJSON * root , const Eventinfo * lf , int archives ){
296
301
if (lf -> location [0 ] == '(' ){
297
- char * e ;
298
- char string [strlen ( lf -> location ) ];
299
- strcpy (string ,lf -> location );
302
+ char * search ;
303
+ char string [MAX_STRING ];
304
+ strncpy (string ,lf -> location , MAX_STRING - 1 );
300
305
int index ;
301
- e = strchr (string , '>' );
302
- index = (int )(e - string );
303
- str_cut (string , 0 , index );
304
- str_cut (string , 0 , 1 );
305
- if (archives == 1 )
306
- cJSON_AddStringToObject (root , "location_desc" , string );
307
- else
308
- cJSON_AddStringToObject (root , "location" , string );
306
+ search = strchr (string , '>' );
307
+ if (search ){
308
+ index = (int )(search - string );
309
+ str_cut (string , 0 , index );
310
+ str_cut (string , 0 , 1 );
311
+
312
+ if (archives == 1 )
313
+ cJSON_AddStringToObject (root , "location_desc" , string );
314
+ else
315
+ cJSON_AddStringToObject (root , "location" , string );
316
+ }
309
317
}else {
310
318
if (archives == 1 )
311
319
cJSON_AddStringToObject (root , "location_desc" , lf -> location );
@@ -382,9 +390,3 @@ void trim(char * s) {
382
390
383
391
memmove (s , p , l + 1 );
384
392
}
385
- void removeChar ( char * string , char letter ) {
386
- unsigned int i ;
387
- for (i = 0 ; i < strlen ( string ); i ++ )
388
- if ( string [i ] == letter )
389
- strcpy ( string + i , string + i + 1 );
390
- }
0 commit comments