aboutsummaryrefslogtreecommitdiffstats
path: root/main/nfdump/fix-security-issues-in-netflow_v9-and-ipfix.patch
blob: b16dba0ff03576e63252800e51df1f541dfa97f6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
From ff0e855bd1f51bed9fc5d8559c64d3cfb475a5d8 Mon Sep 17 00:00:00 2001
From: Peter Haag <peter@Peters-Mac.local>
Date: Sat, 7 May 2016 08:35:34 +0200
Subject: [PATCH] Fix security issues in netflow_v9.c and ipfix.c

---
 bin/ipfix.c      | 88 +++++++++++++++++++++++++++++++++++---------------------
 bin/netflow_v9.c | 81 +++++++++++++++++++++++++++------------------------
 2 files changed, 98 insertions(+), 71 deletions(-)

diff --git a/bin/ipfix.c b/bin/ipfix.c
index ba071ea..f998b72 100644
--- a/bin/ipfix.c
+++ b/bin/ipfix.c
@@ -42,7 +42,6 @@
 #include <sys/socket.h>
 #include <unistd.h>
 #include <stdlib.h>
-#include <syslog.h>
 #include <string.h>
 #include <errno.h>
 #include <time.h>
@@ -322,7 +321,7 @@ int i;
 	cache.lookup_info	    = (struct element_param_s *)calloc(65536, sizeof(struct element_param_s));
 	cache.common_extensions = (uint32_t *)malloc((Max_num_extensions+1)*sizeof(uint32_t));
 	if ( !cache.common_extensions || !cache.lookup_info ) {
-		syslog(LOG_ERR, "Process_ipfix: Panic! malloc(): %s line %d: %s", __FILE__, __LINE__, strerror (errno));
+		LogError("Process_ipfix: Panic! malloc(): %s line %d: %s", __FILE__, __LINE__, strerror (errno));
 		return 0;
 	}
 
@@ -336,7 +335,7 @@ int i;
 	}
 	cache.max_ipfix_elements = i;
 
-	syslog(LOG_DEBUG,"Init IPFIX: Max number of IPFIX tags: %u", cache.max_ipfix_elements);
+	LogError("Init IPFIX: Max number of IPFIX tags: %u", cache.max_ipfix_elements);
 
 	return 1;
 
@@ -370,7 +369,7 @@ uint32_t ObservationDomain = ntohl(ipfix_header->ObservationDomain);
 	// nothing found
 	*e = (exporter_ipfix_domain_t *)malloc(sizeof(exporter_ipfix_domain_t));
 	if ( !(*e)) {
-		syslog(LOG_ERR, "Process_ipfix: Panic! malloc() %s line %d: %s", __FILE__, __LINE__, strerror (errno));
+		LogError("Process_ipfix: Panic! malloc() %s line %d: %s", __FILE__, __LINE__, strerror (errno));
 		return NULL;
 	}
 	memset((void *)(*e), 0, sizeof(exporter_ipfix_domain_t));
@@ -392,7 +391,7 @@ uint32_t ObservationDomain = ntohl(ipfix_header->ObservationDomain);
 
 	dbg_printf("[%u] New exporter: SysID: %u, Observation domain %u from: %s\n", 
 		ObservationDomain, (*e)->info.sysid, ObservationDomain, ipstr);
-	syslog(LOG_INFO, "Process_ipfix: New exporter: SysID: %u, Observation domain %u from: %s\n", 
+	LogInfo("Process_ipfix: New exporter: SysID: %u, Observation domain %u from: %s\n", 
 		(*e)->info.sysid, ObservationDomain, ipstr);
 
 
@@ -460,12 +459,12 @@ input_translation_t **table;
 	// so template refreshing may change the table size without danger of overflowing 
 	*table = calloc(1, sizeof(input_translation_t));
 	if ( !(*table) ) {
-			syslog(LOG_ERR, "Process_ipfix: Panic! calloc() %s line %d: %s", __FILE__, __LINE__, strerror (errno));
+			LogError("Process_ipfix: Panic! calloc() %s line %d: %s", __FILE__, __LINE__, strerror (errno));
 			return NULL;
 	}
 	(*table)->sequence = calloc(cache.max_ipfix_elements, sizeof(sequence_map_t));
 	if ( !(*table)->sequence ) {
-			syslog(LOG_ERR, "Process_ipfix: Panic! malloc() %s line %d: %s", __FILE__, __LINE__, strerror (errno));
+			LogError("Process_ipfix: Panic! malloc() %s line %d: %s", __FILE__, __LINE__, strerror (errno));
 			return NULL;
 	}
 
@@ -481,7 +480,7 @@ input_translation_t **table;
 static void remove_translation_table(FlowSource_t *fs, exporter_ipfix_domain_t *exporter, uint16_t id) {
 input_translation_t *table, *parent;
 
-	syslog(LOG_INFO, "Process_ipfix: [%u] Withdraw template id: %i", 
+	LogInfo("Process_ipfix: [%u] Withdraw template id: %i", 
 			exporter->info.id, id);
 
 	parent = NULL;
@@ -492,7 +491,7 @@ input_translation_t *table, *parent;
 	}
 
 	if ( table == NULL ) {
-		syslog(LOG_ERR, "Process_ipfix: [%u] Withdraw template id: %i. translation table not found", 
+		LogError("Process_ipfix: [%u] Withdraw template id: %i. translation table not found", 
 				exporter->info.id, id);
 		return;
 	}
@@ -521,7 +520,7 @@ input_translation_t *table, *parent;
 static void remove_all_translation_tables(exporter_ipfix_domain_t *exporter) {
 input_translation_t *table, *next;
 
-	syslog(LOG_INFO, "Process_ipfix: Withdraw all templates from observation domain %u\n", 
+	LogInfo("Process_ipfix: Withdraw all templates from observation domain %u\n", 
 		exporter->info.id);
 
 	table = exporter->input_translation_table;
@@ -548,7 +547,7 @@ uint32_t i = table->number_of_sequences;
 uint32_t index = cache.lookup_info[Type].index;
 
 	if ( table->number_of_sequences >= cache.max_ipfix_elements ) {
-		syslog(LOG_ERR, "Process_ipfix: Software bug! Sequence table full. at %s line %d", 
+		LogError("Process_ipfix: Software bug! Sequence table full. at %s line %d", 
 			__FILE__, __LINE__);
 		dbg_printf("Software bug! Sequence table full. at %s line %d", 
 			__FILE__, __LINE__);
@@ -584,7 +583,7 @@ size_t				size_required;
 
 	table = GetTranslationTable(exporter, id);
 	if ( !table ) {
-		syslog(LOG_INFO, "Process_ipfix: [%u] Add template %u", exporter->info.id, id);
+		LogInfo("Process_ipfix: [%u] Add template %u", exporter->info.id, id);
 		table = add_translation_table(exporter, id);
 		if ( !table ) {
 			return NULL;
@@ -597,7 +596,7 @@ size_t				size_required;
 		size_required = (size_required + 3) &~(size_t)3;
 		extension_map = malloc(size_required);
 		if ( !extension_map ) {
-			syslog(LOG_ERR, "Process_ipfix: Panic! malloc() error in %s line %d: %s", __FILE__, __LINE__, strerror (errno));
+			LogError("Process_ipfix: Panic! malloc() error in %s line %d: %s", __FILE__, __LINE__, strerror (errno));
 			return  NULL;
 		}
 		extension_map->type 	   = ExtensionMapType;
@@ -912,6 +911,13 @@ uint16_t Offset = 0;
 	// a template flowset can contain multiple records ( templates )
 	while ( size_left ) {
 
+		if ( size_left && size_left < 4 ) {
+			LogError("Process_ipfix [%u] Template size error at %s line %u" , 
+				exporter->info.id, __FILE__, __LINE__, strerror (errno));
+			size_left = 0;
+			continue;
+		}
+
 		// clear helper tables
 		memset((void *)cache.common_extensions, 0,  (Max_num_extensions+1)*sizeof(uint32_t));
 		memset((void *)cache.lookup_info, 0, 65536 * sizeof(struct element_param_s));
@@ -940,7 +946,7 @@ uint16_t Offset = 0;
 		size_required   = 4*count;
 		if ( size_left < size_required ) {
 			// if we fail this check, this flowset must be skipped.
-			syslog(LOG_ERR, "Process_ipfix: [%u] Not enough data for template elements! required: %i, left: %u", 
+			LogError("Process_ipfix: [%u] Not enough data for template elements! required: %i, left: %u", 
 					exporter->info.id, size_required, size_left);
 			dbg_printf("ERROR: Not enough data for template elements! required: %i, left: %u", size_required, size_left);
 			return;
@@ -974,7 +980,7 @@ uint16_t Offset = 0;
 				ipfix_template_elements_e_t *e = (ipfix_template_elements_e_t *)NextElement;
 				size_required += 4;	// ad 4 for enterprise value
 				if ( size_left < size_required ) {
-					syslog(LOG_ERR, "Process_ipfix: [%u] Not enough data for template elements! required: %i, left: %u", 
+					LogError("Process_ipfix: [%u] Not enough data for template elements! required: %i, left: %u", 
 							exporter->info.id, size_required, size_left);
 					dbg_printf("ERROR: Not enough data for template elements! required: %i, left: %u", size_required, size_left);
 					return;
@@ -1097,7 +1103,7 @@ uint16_t	offset_std_sampler_interval, offset_std_sampler_algorithm, found_std_sa
 	i = 0;	// keep compiler happy
 	size_left 		  = GET_FLOWSET_LENGTH(option_template_flowset) - 4; // -4 for flowset header -> id and length
 	if ( size_left < 6 ) {
-		syslog(LOG_ERR, "Process_ipfix: [%u] option template length error: size left %u too small for an options template", 
+		LogError("Process_ipfix: [%u] option template length error: size left %u too small for an options template", 
 			exporter->info.id, size_left);
 		return;
 	}
@@ -1110,16 +1116,16 @@ uint16_t	offset_std_sampler_interval, offset_std_sampler_algorithm, found_std_sa
 	size_left -= 6;
 
 	if ( scope_field_count == 0  ) {
-		syslog(LOG_ERR, "Process_ipfx: [%u] scope field count error: length must not be zero", 
+		LogError("Process_ipfx: [%u] scope field count error: length must not be zero", 
 			exporter->info.id);
 		dbg_printf("scope field count error: length must not be zero\n");
 		return;
 	}
 
-	size_required = field_count * 2 * sizeof(uint16_t);
+	size_required = (field_count + scope_field_count) * 2 * sizeof(uint16_t);
 	dbg_printf("Size left: %u, size required: %u\n", size_left, size_required);
 	if ( size_left < size_required ) {
-		syslog(LOG_ERR, "Process_ipfix: [%u] option template length error: size left %u too small for %u scopes length and %u options length", 
+		LogError("Process_ipfix: [%u] option template length error: size left %u too small for %u scopes length and %u options length", 
 			exporter->info.id, size_left, field_count, scope_field_count);
 		dbg_printf("option template length error: size left %u too small for field_count %u\n", 
 			size_left, field_count);
@@ -1130,7 +1136,7 @@ uint16_t	offset_std_sampler_interval, offset_std_sampler_algorithm, found_std_sa
 		id, field_count, scope_field_count);
 
 	if ( scope_field_count == 0  ) {
-		syslog(LOG_ERR, "Process_ipfxi: [%u] scope field count error: length must not be zero", 
+		LogError("Process_ipfxi: [%u] scope field count error: length must not be zero", 
 			exporter->info.id);
 		return;
 	}
@@ -1140,14 +1146,20 @@ uint16_t	offset_std_sampler_interval, offset_std_sampler_algorithm, found_std_sa
 		uint16_t id, length;
 		int Enterprise;
 
+		if ( size_left && size_left < 4 ) {
+			LogError("Process_ipfix [%u] Template size error at %s line %u" , 
+				exporter->info.id, __FILE__, __LINE__, strerror (errno));
+			return;
+		}
 		id 	   = Get_val16(DataPtr); DataPtr += 2;
 		length = Get_val16(DataPtr); DataPtr += 2;
+		size_left -= 4;
 		Enterprise = id & 0x8000 ? 1 : 0;
 		if ( Enterprise ) {
 			size_required += 4;
 			dbg_printf("Adjusted: Size left: %u, size required: %u\n", size_left, size_required);
 			if ( size_left < size_required ) {
-				syslog(LOG_ERR, "Process_ipfix: [%u] option template length error: size left %u too small for %u scopes length and %u options length", 
+				LogError("Process_ipfix: [%u] option template length error: size left %u too small for %u scopes length and %u options length", 
 					exporter->info.id, size_left, field_count, scope_field_count);
 				dbg_printf("option template length error: size left %u too small for field_count %u\n", 
 					size_left, field_count);
@@ -1155,6 +1167,7 @@ uint16_t	offset_std_sampler_interval, offset_std_sampler_algorithm, found_std_sa
 			}
 			enterprise_value = Get_val32(DataPtr);
 			DataPtr += 4;
+			size_left -= 4;
 			dbg_printf(" [%i] Enterprise: 1, scope id: %u, scope length %u enterprise value: %u\n", 
 				i, id, length, enterprise_value);
 		} else {
@@ -1168,12 +1181,13 @@ uint16_t	offset_std_sampler_interval, offset_std_sampler_algorithm, found_std_sa
 
 		id 	   = Get_val16(DataPtr); DataPtr += 2;
 		length = Get_val16(DataPtr); DataPtr += 2;
+		size_left -= 4;
 		Enterprise = id & 0x8000 ? 1 : 0;
 		if ( Enterprise ) {
 			size_required += 4;
 			dbg_printf("Adjusted: Size left: %u, size required: %u\n", size_left, size_required);
 			if ( size_left < size_required ) {
-				syslog(LOG_ERR, "Process_ipfix: [%u] option template length error: size left %u too small for %u scopes length and %u options length", 
+				LogError("Process_ipfix: [%u] option template length error: size left %u too small for %u scopes length and %u options length", 
 					exporter->info.id, size_left, field_count, scope_field_count);
 				dbg_printf("option template length error: size left %u too small for field_count %u\n", 
 					size_left, field_count);
@@ -1181,6 +1195,7 @@ uint16_t	offset_std_sampler_interval, offset_std_sampler_algorithm, found_std_sa
 			}
 			enterprise_value = Get_val32(DataPtr);
 			DataPtr += 4;
+			size_left -= 4;
 			dbg_printf(" [%i] Enterprise: 1, option id: %u, option length %u enterprise value: %u\n", 
 				i, id, length, enterprise_value);
 		} else {
@@ -1300,7 +1315,7 @@ char				*string;
 
 		if ( (size_left < table->input_record_size) ) {
 			if ( size_left > 3 ) {
-				syslog(LOG_WARNING,"Process_ipfix: Corrupt data flowset? Pad bytes: %u", size_left);
+				LogError("Process_ipfix: Corrupt data flowset? Pad bytes: %u", size_left);
 				dbg_printf("Process_ipfix: Corrupt data flowset? Pad bytes: %u, table record_size: %u\n", 
 					size_left, table->input_record_size);
 			}
@@ -1311,7 +1326,7 @@ char				*string;
 		// check for enough space in output buffer
 		if ( !CheckBufferSpace(fs->nffile, table->output_record_size) ) {
 			// this should really never occur, because the buffer gets flushed ealier
-			syslog(LOG_ERR,"Process_ipfix: output buffer size error. Abort ipfix record processing");
+			LogError("Process_ipfix: output buffer size error. Abort ipfix record processing");
 			dbg_printf("Process_ipfix: output buffer size error. Abort ipfix record processing");
 			return;
 		}
@@ -1455,7 +1470,7 @@ char				*string;
 					break;
 				
 				default:
-					syslog(LOG_ERR, "Process_ipfix: Software bug! Unknown Sequence: %u. at %s line %d", 
+					LogError("Process_ipfix: Software bug! Unknown Sequence: %u. at %s line %d", 
 						table->sequence[i].id, __FILE__, __LINE__);
 					dbg_printf("Software bug! Unknown Sequence: %u. at %s line %d\n", 
 						table->sequence[i].id, __FILE__, __LINE__);
@@ -1587,9 +1602,9 @@ char				*string;
 		// buffer size sanity check
 		if ( fs->nffile->block_header->size  > BUFFSIZE ) {
 			// should never happen
-			syslog(LOG_ERR,"### Software error ###: %s line %d", __FILE__, __LINE__);
-			syslog(LOG_ERR,"Process ipfix: Output buffer overflow! Flush buffer and skip records.");
-			syslog(LOG_ERR,"Buffer size: %u > %u", fs->nffile->block_header->size, BUFFSIZE);
+			LogError("### Software error ###: %s line %d", __FILE__, __LINE__);
+			LogError("Process ipfix: Output buffer overflow! Flush buffer and skip records.");
+			LogError("Buffer size: %u > %u", fs->nffile->block_header->size, BUFFSIZE);
 
 			// reset buffer
 			fs->nffile->block_header->size 		= 0;
@@ -1614,7 +1629,7 @@ static uint32_t		packet_cntr = 0;
 
 	size_left 	 = in_buff_cnt;
 	if ( size_left < IPFIX_HEADER_LENGTH ) {
-		syslog(LOG_ERR, "Process_ipfix: Too little data for ipfix packet: '%lli'", (long long)size_left);
+		LogError("Process_ipfix: Too little data for ipfix packet: '%lli'", (long long)size_left);
 		return;
 	}
 
@@ -1625,7 +1640,7 @@ static uint32_t		packet_cntr = 0;
 
 	exporter	= GetExporter(fs, ipfix_header);
 	if ( !exporter ) {
-		syslog(LOG_ERR,"Process_ipfix: Exporter NULL: Abort ipfix record processing");
+		LogError("Process_ipfix: Exporter NULL: Abort ipfix record processing");
 		return;
 	}
 	exporter->packets++;
@@ -1665,6 +1680,13 @@ static uint32_t		packet_cntr = 0;
 	while (size_left) {
 		uint16_t	flowset_id;
 
+		if ( size_left && size_left < 4 ) {
+			LogError("Process_ipfix [%u] Template size error at %s line %u" , 
+				exporter->info.id, __FILE__, __LINE__, strerror (errno));
+			size_left = 0;
+			continue;
+		}
+
 		flowset_header = flowset_header + flowset_length;
 
 		flowset_id 		= GET_FLOWSET_ID(flowset_header);
@@ -1677,7 +1699,7 @@ static uint32_t		packet_cntr = 0;
 				and smaller is an illegal flowset anyway ...
 				if it happends, we can't determine the next flowset, so skip the entire export packet
 			 */
-			syslog(LOG_ERR,"Process_ipfix: flowset zero length error.");
+			LogError("Process_ipfix: flowset zero length error.");
 			dbg_printf("Process_ipfix: flowset zero length error.\n");
 			return;
 
@@ -1690,7 +1712,7 @@ static uint32_t		packet_cntr = 0;
 		}
 
 		if ( flowset_length > size_left ) {
-			syslog(LOG_ERR,"Process_ipfix: flowset length error. Expected bytes: %u > buffersize: %lli", 
+			LogError("Process_ipfix: flowset length error. Expected bytes: %u > buffersize: %lli", 
 				flowset_length, (long long)size_left);
 			size_left = 0;
 			continue;
@@ -1713,7 +1735,7 @@ static uint32_t		packet_cntr = 0;
 			default: {
 				if ( flowset_id < IPFIX_MIN_RECORD_FLOWSET_ID ) {
 					dbg_printf("Invalid flowset id: %u. Skip flowset\n", flowset_id);
-					syslog(LOG_ERR,"Process_ipfix: Invalid flowset id: %u. Skip flowset", flowset_id);
+					LogError("Process_ipfix: Invalid flowset id: %u. Skip flowset", flowset_id);
 				} else {
 					input_translation_t *table;
 					dbg_printf("Process data flowset, length: %u\n", flowset_length);
diff --git a/bin/netflow_v9.c b/bin/netflow_v9.c
index 1264ee3..55386c7 100644
--- a/bin/netflow_v9.c
+++ b/bin/netflow_v9.c
@@ -43,7 +43,6 @@
 #include <sys/socket.h>
 #include <unistd.h>
 #include <stdlib.h>
-#include <syslog.h>
 #include <string.h>
 #include <errno.h>
 #include <time.h>
@@ -451,7 +450,7 @@ int i;
 	cache.lookup_info	    = (struct element_param_s *)calloc(65536, sizeof(struct element_param_s));
 	cache.common_extensions = (uint32_t *)malloc((Max_num_extensions+1)*sizeof(uint32_t));
 	if ( !cache.common_extensions || !cache.lookup_info ) {
-		syslog(LOG_ERR, "Process_v9: Panic! malloc(): %s line %d: %s", __FILE__, __LINE__, strerror (errno));
+		LogError( "Process_v9: Panic! malloc(): %s line %d: %s", __FILE__, __LINE__, strerror (errno));
 		return 0;
 	}
 
@@ -465,7 +464,7 @@ int i;
 	}
 	cache.max_v9_elements = i;
 
-	syslog(LOG_DEBUG,"Init v9: Max number of v9 tags: %u", cache.max_v9_elements);
+	dbg_printf("Init v9: Max number of v9 tags: %u", cache.max_v9_elements);
 
 
 	return 1;
@@ -499,7 +498,7 @@ exporter_v9_domain_t **e = (exporter_v9_domain_t **)&(fs->exporter_data);
 	// nothing found
 	*e = (exporter_v9_domain_t *)malloc(sizeof(exporter_v9_domain_t));
 	if ( !(*e)) {
-		syslog(LOG_ERR, "Process_v9: Panic! malloc() %s line %d: %s", __FILE__, __LINE__, strerror (errno));
+		LogError( "Process_v9: Panic! malloc() %s line %d: %s", __FILE__, __LINE__, strerror (errno));
 		return NULL;
 	}
 	memset((void *)(*e), 0, sizeof(exporter_v9_domain_t));
@@ -521,7 +520,7 @@ exporter_v9_domain_t **e = (exporter_v9_domain_t **)&(fs->exporter_data);
 
 	dbg_printf("Process_v9: New exporter: SysID: %u, Domain: %u, IP: %s\n", 
 		(*e)->info.sysid, exporter_id, ipstr);
-	syslog(LOG_INFO, "Process_v9: New exporter: SysID: %u, Domain: %u, IP: %s\n", 
+	LogInfo("Process_v9: New exporter: SysID: %u, Domain: %u, IP: %s\n", 
 		(*e)->info.sysid, exporter_id, ipstr);
 
 
@@ -591,12 +590,12 @@ input_translation_t **table;
 	// so template refreshing may change the table size without danger of overflowing 
 	*table = calloc(1, sizeof(input_translation_t));
 	if ( !(*table) ) {
-			syslog(LOG_ERR, "Process_v9: Panic! calloc() %s line %d: %s", __FILE__, __LINE__, strerror (errno));
+			LogError( "Process_v9: Panic! calloc() %s line %d: %s", __FILE__, __LINE__, strerror (errno));
 			return NULL;
 	}
 	(*table)->sequence = calloc(cache.max_v9_elements, sizeof(sequence_map_t));
 	if ( !(*table)->sequence ) {
-			syslog(LOG_ERR, "Process_v9: Panic! malloc() %s line %d: %s", __FILE__, __LINE__, strerror (errno));
+			LogError( "Process_v9: Panic! malloc() %s line %d: %s", __FILE__, __LINE__, strerror (errno));
 			return NULL;
 	}
 
@@ -614,7 +613,7 @@ uint32_t i = table->number_of_sequences;
 uint32_t index = cache.lookup_info[Type].index;
 
 	if ( table->number_of_sequences >= cache.max_v9_elements ) {
-		syslog(LOG_ERR, "Process_v9: Software bug! Sequence table full. at %s line %d", 
+		LogError( "Process_v9: Software bug! Sequence table full. at %s line %d", 
 			__FILE__, __LINE__);
 		dbg_printf("Software bug! Sequence table full. at %s line %d", 
 			__FILE__, __LINE__);
@@ -656,7 +655,7 @@ size_t				size_required;
 
 	table = GetTranslationTable(exporter, id);
 	if ( !table ) {
-		syslog(LOG_INFO, "Process_v9: [%u] Add template %u", exporter->info.id, id);
+		LogInfo( "Process_v9: [%u] Add template %u", exporter->info.id, id);
 		dbg_printf("[%u] Add template %u\n", exporter->info.id, id);
 		table = add_translation_table(exporter, id);
 		if ( !table ) {
@@ -670,7 +669,7 @@ size_t				size_required;
 		size_required = (size_required + 3) &~(size_t)3;
 		extension_map = malloc(size_required);
 		if ( !extension_map ) {
-			syslog(LOG_ERR, "Process_v9: Panic! malloc() error in %s line %d: %s", __FILE__, __LINE__, strerror (errno));
+			LogError( "Process_v9: Panic! malloc() error in %s line %d: %s", __FILE__, __LINE__, strerror (errno));
 			return  NULL;
 		}
 		extension_map->type 	   = ExtensionMapType;
@@ -1099,7 +1098,7 @@ size_t				size_required;
 				dbg_printf("%d byte Sampling ID included at offset %u\n", length, table->sampler_offset);
 				break;
 			default:
-				syslog(LOG_ERR, "Process_v9: Unexpected SAMPLER ID field length: %d", 
+				LogError( "Process_v9: Unexpected SAMPLER ID field length: %d", 
 					cache.lookup_info[NF9_FLOW_SAMPLER_ID].length);
 				dbg_printf("Unexpected SAMPLER ID field length: %d", 
 					cache.lookup_info[NF9_FLOW_SAMPLER_ID].length);
@@ -1189,7 +1188,7 @@ option_offset_t	**t;
 			fprintf(stderr, "malloc() allocation error: %s\n", strerror(errno));
 			return ;
 		} 
-		syslog(LOG_ERR, "Process_v9: New std sampler: interval: %i, algorithm: %i", 
+		LogError( "Process_v9: New std sampler: interval: %i, algorithm: %i", 
 			offset_std_sampler_interval, offset_std_sampler_algorithm);
 	}	// else existing table
 
@@ -1240,7 +1239,7 @@ int			i;
 		dbg_printf("template size: %u buffersize: %u\n", size_required, size_left);
 
 		if ( size_left < size_required ) {
-			syslog(LOG_ERR, "Process_v9: [%u] buffer size error: expected %u available %u", 
+			LogError( "Process_v9: [%u] buffer size error: expected %u available %u", 
 				exporter->info.id, size_required, size_left);
 			size_left = 0;
 			continue;
@@ -1348,19 +1347,19 @@ uint16_t	offset_std_sampler_interval, offset_std_sampler_algorithm, found_std_sa
 	option_length 	= GET_OPTION_TEMPLATE_OPTION_LENGTH(option_template);
 
 	if ( scope_length & 0x3 ) {
-		syslog(LOG_ERR, "Process_v9: [%u] scope length error: length %u not multiple of 4", 
+		LogError( "Process_v9: [%u] scope length error: length %u not multiple of 4", 
 			exporter->info.id, scope_length);
 		return;
 	}
 
 	if ( option_length & 0x3 ) {
-		syslog(LOG_ERR, "Process_v9: [%u] option length error: length %u not multiple of 4", 
+		LogError( "Process_v9: [%u] option length error: length %u not multiple of 4", 
 			exporter->info.id, option_length);
 		return;
 	}
 
 	if ( (scope_length + option_length) > size_left ) {
-		syslog(LOG_ERR, "Process_v9: [%u] option template length error: size left %u too small for %u scopes length and %u options length", 
+		LogError( "Process_v9: [%u] option template length error: size left %u too small for %u scopes length and %u options length", 
 			exporter->info.id, size_left, scope_length, option_length);
 		return;
 	}
@@ -1410,7 +1409,7 @@ uint16_t	offset_std_sampler_interval, offset_std_sampler_algorithm, found_std_sa
 		}
 
 		if ( index && v9_element_map[index].length != length ) {
-			syslog(LOG_ERR,"Process_v9: Option field Type: %u, length %u not supported\n", type, length);
+			LogError("Process_v9: Option field Type: %u, length %u not supported\n", type, length);
 			dbg_printf("Process_v9: Option field Type: %u, length %u not supported\n", type, length);
 			continue;
 		}
@@ -1529,9 +1528,15 @@ char				*string;
 	while (size_left) {
 		common_record_t		*data_record;
 
+		if ( (table->input_record_size == 0 )) {
+			LogError("Process_v9: Corrupt data flowset? table input_record_sizei = 0 ");
+			size_left = 0;
+			continue;
+		}
+
 		if ( (size_left < table->input_record_size) ) {
 			if ( size_left > 3 ) {
-				syslog(LOG_WARNING,"Process_v9: Corrupt data flowset? Pad bytes: %u", size_left);
+				LogError("Process_v9: Corrupt data flowset? Pad bytes: %u", size_left);
 				dbg_printf("Process_v9: Corrupt data flowset? Pad bytes: %u, table record_size: %u\n", 
 					size_left, table->input_record_size);
 			}
@@ -1542,7 +1547,7 @@ char				*string;
 		// check for enough space in output buffer
 		if ( !CheckBufferSpace(fs->nffile, table->output_record_size) ) {
 			// this should really never occur, because the buffer gets flushed ealier
-			syslog(LOG_ERR,"Process_v9: output buffer size error. Abort v9 record processing");
+			LogError("Process_v9: output buffer size error. Abort v9 record processing");
 			dbg_printf("Process_v9: output buffer size error. Abort v9 record processing");
 			return;
 		}
@@ -1738,7 +1743,7 @@ char				*string;
 						*((uint32_t *)&out[output_offset+12]) = 0;
 					} break;
 				default:
-					syslog(LOG_ERR, "Process_v9: Software bug! Unknown Sequence: %u. at %s line %d", 
+					LogError( "Process_v9: Software bug! Unknown Sequence: %u. at %s line %d", 
 						table->sequence[i].id, __FILE__, __LINE__);
 					dbg_printf("Software bug! Unknown Sequence: %u. at %s line %d", 
 						table->sequence[i].id, __FILE__, __LINE__);
@@ -1936,9 +1941,9 @@ char				*string;
 		// buffer size sanity check
 		if ( fs->nffile->block_header->size  > BUFFSIZE ) {
 			// should never happen
-			syslog(LOG_ERR,"### Software error ###: %s line %d", __FILE__, __LINE__);
-			syslog(LOG_ERR,"Process v9: Output buffer overflow! Flush buffer and skip records.");
-			syslog(LOG_ERR,"Buffer size: %u > %u", fs->nffile->block_header->size, BUFFSIZE);
+			LogError("### Software error ###: %s line %d", __FILE__, __LINE__);
+			LogError("Process v9: Output buffer overflow! Flush buffer and skip records.");
+			LogError("Buffer size: %u > %u", fs->nffile->block_header->size, BUFFSIZE);
 
 			// reset buffer
 			fs->nffile->block_header->size 		= 0;
@@ -1963,7 +1968,7 @@ uint8_t		*in;
 
 	if ( !offset_table ) {
 		// should never happen - catch it anyway
-		syslog(LOG_ERR, "Process_v9: Panic! - No Offset table found! : %s line %d", __FILE__, __LINE__);
+		LogError( "Process_v9: Panic! - No Offset table found! : %s line %d", __FILE__, __LINE__);
 		return;
 	}
 
@@ -2007,7 +2012,7 @@ uint8_t		*in;
 		dbg_printf("Sampler algorithm: %u\n", mode);
 		dbg_printf("Sampler interval : %u\n", interval);
 
-		syslog(LOG_INFO, "Set std sampler: algorithm: %u, interval: %u\n", 
+		LogInfo( "Set std sampler: algorithm: %u, interval: %u\n", 
 				mode, interval);
 		dbg_printf("Set std sampler: algorithm: %u, interval: %u\n", 
 				mode, interval);
@@ -2029,7 +2034,7 @@ static int pkg_num = 0;
 	pkg_num++;
 	size_left = in_buff_cnt;
 	if ( size_left < NETFLOW_V9_HEADER_LENGTH ) {
-		syslog(LOG_ERR, "Process_v9: Too little data for v9 packet: '%lli'", (long long)size_left);
+		LogError( "Process_v9: Too little data for v9 packet: '%lli'", (long long)size_left);
 		return;
 	}
 
@@ -2039,7 +2044,7 @@ static int pkg_num = 0;
 
 	exporter	= GetExporter(fs, exporter_id);
 	if ( !exporter ) {
-		syslog(LOG_ERR,"Process_v9: Exporter NULL: Abort v9 record processing");
+		LogError("Process_v9: Exporter NULL: Abort v9 record processing");
 		return;
 	}
 	exporter->packets++;
@@ -2078,7 +2083,7 @@ static int pkg_num = 0;
 				exporter->info.id, (long long)exporter->last_sequence, (long long)exporter->sequence, (long long)distance);
 			/*
 			if ( report_seq ) 
-				syslog(LOG_ERR,"Flow sequence mismatch. Missing: %lli packets", delta(last_count,distance));
+				LogError("Flow sequence mismatch. Missing: %lli packets", delta(last_count,distance));
 			*/
 		}
 	}
@@ -2102,7 +2107,7 @@ static int pkg_num = 0;
 				and smaller is an illegal flowset anyway ...
 				if it happends, we can't determine the next flowset, so skip the entire export packet
 			 */
-			syslog(LOG_ERR,"Process_v9: flowset zero length error.");
+			LogError("Process_v9: flowset zero length error.");
 			dbg_printf("Process_v9: flowset zero length error.\n");
 			return;
 		}
@@ -2116,7 +2121,7 @@ static int pkg_num = 0;
 		if ( flowset_length > size_left ) {
 			dbg_printf("flowset length error. Expected bytes: %u > buffersize: %lli", 
 				flowset_length, (long long)size_left);
-			syslog(LOG_ERR,"Process_v9: flowset length error. Expected bytes: %u > buffersize: %lli", 
+			LogError("Process_v9: flowset length error. Expected bytes: %u > buffersize: %lli", 
 				flowset_length, (long long)size_left);
 			size_left = 0;
 			continue;
@@ -2135,14 +2140,14 @@ static int pkg_num = 0;
 				break;
 			case NF9_OPTIONS_FLOWSET_ID:
 				option_flowset = (option_template_flowset_t *)flowset_header;
-				syslog(LOG_DEBUG,"Process_v9: Found options flowset: template %u", ntohs(option_flowset->template_id));
+				dbg_printf("Process_v9: Found options flowset: template %u", ntohs(option_flowset->template_id));
 				Process_v9_option_templates(exporter, flowset_header, fs);
 				break;
 			default: {
 				input_translation_t *table;
 				if ( flowset_id < NF9_MIN_RECORD_FLOWSET_ID ) {
 					dbg_printf("Invalid flowset id: %u\n", flowset_id);
-					syslog(LOG_ERR,"Process_v9: Invalid flowset id: %u", flowset_id);
+					LogError("Process_v9: Invalid flowset id: %u", flowset_id);
 				} else {
 
 					dbg_printf("[%u] ID %u Data flowset\n", exporter->info.id, flowset_id);
@@ -2168,7 +2173,7 @@ static int pkg_num = 0;
 
 #ifdef DEVEL
 	if ( processed_records != expected_records ) {
-		syslog(LOG_ERR, "Process_v9: Processed records %u, expected %u", processed_records, expected_records);
+		LogError( "Process_v9: Processed records %u, expected %u", processed_records, expected_records);
 		printf("Process_v9: Processed records %u, expected %u\n", processed_records, expected_records);
 	}
 #endif
@@ -2990,7 +2995,7 @@ generic_sampler_t *sampler;
 		// no samplers so far 
 		sampler = (generic_sampler_t *)malloc(sizeof(generic_sampler_t));
 		if ( !sampler ) {
-			syslog(LOG_ERR, "Process_v9: Panic! malloc(): %s line %d: %s", __FILE__, __LINE__, strerror (errno));
+			LogError( "Process_v9: Panic! malloc(): %s line %d: %s", __FILE__, __LINE__, strerror (errno));
 			return;
 		}
 
@@ -3004,7 +3009,7 @@ generic_sampler_t *sampler;
 		exporter->sampler = sampler;
 
 		FlushInfoSampler(fs, &(sampler->info));
-		syslog(LOG_INFO, "Add new sampler: ID: %i, mode: %u, interval: %u\n", 
+		LogInfo( "Add new sampler: ID: %i, mode: %u, interval: %u\n", 
 			id, mode, interval);
 		dbg_printf("Add new sampler: ID: %i, mode: %u, interval: %u\n", 
 			id, mode, interval);
@@ -3015,7 +3020,7 @@ generic_sampler_t *sampler;
 			// test for update of existing sampler
 			if ( sampler->info.id == id ) {
 				// found same sampler id - update record
-				syslog(LOG_INFO, "Update existing sampler id: %i, mode: %u, interval: %u\n", 
+				LogInfo( "Update existing sampler id: %i, mode: %u, interval: %u\n", 
 					id, mode, interval);
 				dbg_printf("Update existing sampler id: %i, mode: %u, interval: %u\n", 
 					id, mode, interval);
@@ -3037,7 +3042,7 @@ generic_sampler_t *sampler;
 				// end of sampler chain - insert new sampler
 				sampler->next = (generic_sampler_t *)malloc(sizeof(generic_sampler_t));
 				if ( !sampler->next ) {
-					syslog(LOG_ERR, "Process_v9: Panic! malloc(): %s line %d: %s", __FILE__, __LINE__, strerror (errno));
+					LogError( "Process_v9: Panic! malloc(): %s line %d: %s", __FILE__, __LINE__, strerror (errno));
 					return;
 				}
 				sampler = sampler->next;
@@ -3053,7 +3058,7 @@ generic_sampler_t *sampler;
 				FlushInfoSampler(fs, &(sampler->info));
 
 
-				syslog(LOG_INFO, "Append new sampler: ID: %u, mode: %u, interval: %u\n", 
+				LogInfo( "Append new sampler: ID: %u, mode: %u, interval: %u\n", 
 					id, mode, interval);
 				dbg_printf("Append new sampler: ID: %u, mode: %u, interval: %u\n", 
 					id, mode, interval);