22# coding=utf-8
33
44from __future__ import absolute_import , division , print_function , unicode_literals
5+
6+ import csv
57import os
68import sys
79
@@ -19,23 +21,29 @@ class DecryptCommand(StreamingCommand):
1921 def stream (self , records ):
2022 stmt = " " .join (self .fieldnames )
2123
22- for record in records :
23- try :
24- decryptlib .g_record = record
25- decryptlib .logger = self .logger
26- exception_string = None
27-
28- if self .field in record :
29- result = record [self .field ]
30-
31- for fn , args in decryptlib .parsestmt (stmt ):
32- result = fn (result , args )
33-
34- except Exception as e :
35- exception_string = str (e )
36- record [".decrypt_failure__" ] = exception_string
37-
38- yield record
24+ try :
25+ for record in records :
26+ try :
27+ decryptlib .g_record = record
28+ decryptlib .logger = self .logger
29+ exception_string = None
30+
31+ if self .field in record :
32+ result = record [self .field ]
33+
34+ for fn , args in decryptlib .parsestmt (stmt ):
35+ result = fn (result , args )
36+
37+ except Exception as e :
38+ exception_string = str (e )
39+ record [".decrypt_failure__" ] = exception_string
40+
41+ yield record
42+ except csv .Error :
43+ raise csv .Error ('Splunk record contained NUL. '
44+ 'Use eval/replace or rex/sed beforehand to work around, '
45+ 'or use the decrypt/escape function in the previous command.'
46+ ' (fixed in Python 3.11)' )
3947
4048
4149dispatch (DecryptCommand , sys .argv , sys .stdin , sys .stdout , __name__ )
0 commit comments