Commit 7b13dc71 authored by ben's avatar ben

Added error checking to middle of file reading, security fix for resuming


git-svn-id: http://svn.savannah.nongnu.org/svn/rdiff-backup@174 2b77aa54-bcbc-44c9-a7ec-4f6cf2b41109
parent 54ffad61
......@@ -108,6 +108,7 @@ def set_allowed_requests(sec_level):
allowed_requests.extend(["C.make_file_dict",
"os.getuid",
"os.listdir",
"Time.setcurtime_local",
"Resume.ResumeCheck",
"HLSourceStruct.split_initial_dsiter",
"HLSourceStruct.get_diffs_and_finalize"])
......@@ -127,7 +128,6 @@ def set_allowed_requests(sec_level):
allowed_requests.extend(["SetConnections.init_connection_remote",
"Log.setverbosity",
"Log.setterm_verbosity",
"Time.setcurtime_local",
"Time.setprevtime_local",
"FilenameMapping.set_init_quote_vals_local",
"Globals.postset_regexp_local",
......
......@@ -190,12 +190,20 @@ class FileWrappingIter:
def addfromfile(self):
"""Read a chunk from the current file and return it"""
buf = self.currently_in_file.read(Globals.blocksize)
# Check file read for errors, buf = "" if find one
buf = Robust.check_common_error(self.read_error_handler,
self.currently_in_file.read,
[Globals.blocksize])
if not buf:
assert not self.currently_in_file.close()
self.currently_in_file = None
return C.long2str(long(len(buf))) + buf
def read_error_handler(self, exc, blocksize):
"""Log error when reading from file"""
Log("Error '%s' reading from fileobj, truncating" % (str(exc),), 2)
return ""
def _l2s_old(self, l):
"""Convert long int to string of 7 characters"""
s = ""
......@@ -237,3 +245,4 @@ class BufferedRead:
def close(self): return self.file.close()
from log import *
from robust import *
......@@ -575,7 +575,10 @@ class Resume:
mirror = None
last_index = cls.sym_to_index(increment_sym)
if checkpoint_rp:
ITR, finalizer = cls.unpickle_checkpoint(checkpoint_rp)
result = cls.unpickle_checkpoint(checkpoint_rp)
sys.stderr.write("#############" + str(result) + "\n")
#ITR, finalizer = cls.unpickle_checkpoint(checkpoint_rp)
ITR, finalizer = result
elif mirror_sym:
mirror = 1
last_index = cls.sym_to_index(mirror_sym)
......@@ -609,6 +612,7 @@ class Resume:
try: result = cPickle.loads(data)
except cPickle.UnpicklingError:
raise ResumeException("Bad pickle at %s" % (checkpoint_rp.path,))
return result
def ResumeCheck(cls):
"""Return relevant ResumeSessionInfo if there's one we should resume
......
......@@ -108,6 +108,7 @@ def set_allowed_requests(sec_level):
allowed_requests.extend(["C.make_file_dict",
"os.getuid",
"os.listdir",
"Time.setcurtime_local",
"Resume.ResumeCheck",
"HLSourceStruct.split_initial_dsiter",
"HLSourceStruct.get_diffs_and_finalize"])
......@@ -127,7 +128,6 @@ def set_allowed_requests(sec_level):
allowed_requests.extend(["SetConnections.init_connection_remote",
"Log.setverbosity",
"Log.setterm_verbosity",
"Time.setcurtime_local",
"Time.setprevtime_local",
"FilenameMapping.set_init_quote_vals_local",
"Globals.postset_regexp_local",
......
......@@ -190,12 +190,20 @@ class FileWrappingIter:
def addfromfile(self):
"""Read a chunk from the current file and return it"""
buf = self.currently_in_file.read(Globals.blocksize)
# Check file read for errors, buf = "" if find one
buf = Robust.check_common_error(self.read_error_handler,
self.currently_in_file.read,
[Globals.blocksize])
if not buf:
assert not self.currently_in_file.close()
self.currently_in_file = None
return C.long2str(long(len(buf))) + buf
def read_error_handler(self, exc, blocksize):
"""Log error when reading from file"""
Log("Error '%s' reading from fileobj, truncating" % (str(exc),), 2)
return ""
def _l2s_old(self, l):
"""Convert long int to string of 7 characters"""
s = ""
......@@ -237,3 +245,4 @@ class BufferedRead:
def close(self): return self.file.close()
from log import *
from robust import *
......@@ -575,7 +575,10 @@ class Resume:
mirror = None
last_index = cls.sym_to_index(increment_sym)
if checkpoint_rp:
ITR, finalizer = cls.unpickle_checkpoint(checkpoint_rp)
result = cls.unpickle_checkpoint(checkpoint_rp)
sys.stderr.write("#############" + str(result) + "\n")
#ITR, finalizer = cls.unpickle_checkpoint(checkpoint_rp)
ITR, finalizer = result
elif mirror_sym:
mirror = 1
last_index = cls.sym_to_index(mirror_sym)
......@@ -609,6 +612,7 @@ class Resume:
try: result = cPickle.loads(data)
except cPickle.UnpicklingError:
raise ResumeException("Bad pickle at %s" % (checkpoint_rp.path,))
return result
def ResumeCheck(cls):
"""Return relevant ResumeSessionInfo if there's one we should resume
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment