Skip to content

Commit 5dc51ea

Browse files
authored
Merge pull request #1618 from atomicturtle/fix-lf-location-array-from-unknow-syslog
Fix lf location array from unknown syslog
2 parents 41310aa + d0c9074 commit 5dc51ea

File tree

2 files changed

+38
-38
lines changed

2 files changed

+38
-38
lines changed

src/analysisd/format/json_extended.c

Lines changed: 38 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -251,15 +251,18 @@ int W_isRootcheck(cJSON *root, int nested){
251251
// ** TODO ** Regex instead str_cut
252252
void W_JSON_ParseHostname(cJSON *root, char *hostname){
253253
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);
257257
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+
263266
}else{
264267
cJSON_AddStringToObject(root, "hostname", hostname);
265268
}
@@ -276,36 +279,41 @@ void W_JSON_ParseHostname(cJSON *root, char *hostname){
276279
// ** TODO ** Regex instead str_cut
277280
void W_JSON_ParseAgentIP(cJSON *root, const Eventinfo *lf){
278281
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);
282285
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+
}
291296
}
292297

293298
}
294299
// The file location usually comes with more information about the alert (like hostname or ip) we will extract just the "/var/folder/file.log".
295300
void W_JSON_ParseLocation(cJSON *root, const Eventinfo *lf, int archives){
296301
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);
300305
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+
}
309317
}else{
310318
if(archives == 1)
311319
cJSON_AddStringToObject(root, "location_desc", lf->location);
@@ -382,9 +390,3 @@ void trim(char * s) {
382390

383391
memmove(s, p, l + 1);
384392
}
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-
}

src/analysisd/format/to_json.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -289,8 +289,6 @@ char *Archiveinfo_to_jsonstr(const Eventinfo *lf)
289289
cJSON_AddNumberToObject(decoder, "fts", lf->decoder_info->fts);
290290
if (lf->decoder_info->accumulate)
291291
cJSON_AddNumberToObject(decoder, "accumulate", lf->decoder_info->accumulate);
292-
if (lf->decoder_info->accumulate)
293-
cJSON_AddNumberToObject(decoder, "accumulate", lf->decoder_info->accumulate);
294292

295293
if (lf->decoder_info->parent)
296294
cJSON_AddStringToObject(decoder, "parent", lf->decoder_info->parent);

0 commit comments

Comments
 (0)