From 78b07506025c71c2cffcd7032961973798ea9690 Mon Sep 17 00:00:00 2001 From: Lukas Oyen Date: Thu, 6 Jul 2017 14:13:09 +0200 Subject: [PATCH] Bug #34648: s4c: ignore corrupted pickle files --- .../modules/univention/s4connector/__init__.py | 31 +++++++++++++++------- 1 file changed, 22 insertions(+), 9 deletions(-) diff --git a/services/univention-s4-connector/modules/univention/s4connector/__init__.py b/services/univention-s4-connector/modules/univention/s4connector/__init__.py index 8eb38c4..51e19d8 100644 --- a/services/univention-s4-connector/modules/univention/s4connector/__init__.py +++ b/services/univention-s4-connector/modules/univention/s4connector/__init__.py @@ -704,12 +704,19 @@ class ucs: ''' sync changes from UCS stored in given file ''' - try: - f = file(filename, 'r') - except IOError: # file not found so there's nothing to sync - return True - dn, new, old, old_dn = cPickle.load(f) + try: + with open(filename) as fob: + (dn, new, old, old_dn) = cPickle.load(fob) + except IOError: + return True # file not found so there's nothing to sync + except (cPickle.UnpicklingError, EOFError) as e: + message = 'file emtpy' if isinstance(e, EOFError) else e.message + ud.debug(ud.LDAP, ud.WARN, + '__sync_file_from_ucs: invalid pickle file {}: {}'.format(filename, message)) + # ignore corrupted pickle file, but safe as rejected to not try again + self._save_rejected_ucs(filename, 'unknown') + return False if dn == 'cn=Subschema': return True @@ -1037,12 +1044,18 @@ class ucs: if not filename == "%s/tmp" % self.baseConfig['%s/s4/listener/dir' % self.CONFIGBASENAME]: if filename not in self.rejected_files: try: - f = file(filename, 'r') - except IOError: # file not found so there's nothing to sync + with open(filename) as fob: + (dn, new, old, old_dn) = cPickle.load(fob) + except IOError: + continue # file not found so there's nothing to sync + except (cPickle.UnpicklingError, EOFError) as e: + message = 'file emtpy' if isinstance(e, EOFError) else e.message + ud.debug(ud.LDAP, ud.WARN, + 'poll_ucs: invalid pickle file {}: {}'.format(filename, message)) + # ignore corrupted pickle file, but safe as rejected to not try again + self._save_rejected_ucs(filename, 'unknown') continue - dn, new, old, old_dn = cPickle.load(f) - for i in [0, 1]: # do it twice if the LDAP connection was closed try: sync_successfull = self.__sync_file_from_ucs(filename, traceback_level=traceback_level) -- 2.7.4