Skip to content

Commit dd29eed

Browse files
committed
Parser: minor fixes in the IPFIX message parser
* fixed conditional jump based on uninitialized value * fixed sequence counter (old out of sequence messages are now ignored)
1 parent 2dc4b25 commit dd29eed

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

src/core/parser.c

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1044,6 +1044,7 @@ ipx_parser_verb(ipx_parser_t *parser, enum ipx_verb_level *v_new, enum ipx_verb_
10441044
int
10451045
ipx_parser_process(ipx_parser_t *parser, ipx_msg_ipfix_t **ipfix, ipx_msg_garbage_t **garbage)
10461046
{
1047+
*garbage = NULL;
10471048
const struct ipx_msg_ctx *msg_ctx = &(*ipfix)->ctx;
10481049
const struct fds_ipfix_msg_hdr *msg_data = (struct fds_ipfix_msg_hdr *)(*ipfix)->raw_pkt;
10491050

@@ -1088,6 +1089,7 @@ ipx_parser_process(ipx_parser_t *parser, ipx_msg_ipfix_t **ipfix, ipx_msg_garbag
10881089
PARSER_DEBUG(parser, msg_ctx, "Processing an IPFIX Message (Seq. number %" PRIu32 ")",
10891090
msg_seq);
10901091

1092+
bool old_oos = false; // Old out of sequence message
10911093
if (info->seq_num != msg_seq) {
10921094
if ((info->flags & SIF_SEEN) == 0) {
10931095
// The first message from this combination of the TS, ODID and Stream ID
@@ -1098,7 +1100,9 @@ ipx_parser_process(ipx_parser_t *parser, ipx_msg_ipfix_t **ipfix, ipx_msg_garbag
10981100
PARSER_WARNING(parser, msg_ctx, "Unexpected Sequence number (expected: "
10991101
"%" PRIu32 ", got: %" PRIu32 ").", info->seq_num, msg_seq);
11001102
if (parser_seq_num_cmp(msg_seq, info->seq_num) > 0) {
1101-
info->seq_num = msg_seq;
1103+
info->seq_num = msg_seq; // Newer than expected
1104+
} else {
1105+
old_oos = true; // Older than expected
11021106
}
11031107
}
11041108
}
@@ -1116,7 +1120,8 @@ ipx_parser_process(ipx_parser_t *parser, ipx_msg_ipfix_t **ipfix, ipx_msg_garbag
11161120
case FDS_ERR_NOTFOUND:
11171121
// Unable to find a corresponding snapshot
11181122
PARSER_WARNING(parser, msg_ctx, "Received IPFIX Message has too old Export Time. "
1119-
"Template are no longer available. All its records are ignored.", 0);
1123+
"Templates are no longer available and therefore, all its data records are "
1124+
"ignored.", 0);
11201125
return IPX_OK;
11211126
case FDS_ERR_NOMEM:
11221127
// Memory allocation failed
@@ -1157,7 +1162,9 @@ ipx_parser_process(ipx_parser_t *parser, ipx_msg_ipfix_t **ipfix, ipx_msg_garbag
11571162
}
11581163

11591164
// Update expected Sequence number of the next message
1160-
info->seq_num += parser_data.data_recs;
1165+
if (!old_oos) {
1166+
info->seq_num += parser_data.data_recs;
1167+
}
11611168

11621169
ipx_msg_garbage_t *garbage_msg = NULL;
11631170
if (parser_data.tmplt_changes) {

0 commit comments

Comments
 (0)