From 5997aca7ceeb25b5434afd164e11a4b7d01d222e Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Sun, 18 Oct 2020 17:28:57 +0200 Subject: _mountinfo: skip mount entires with non-absolute root --- lbup/_mountinfo.py | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/lbup/_mountinfo.py b/lbup/_mountinfo.py index 110eb6c..e687e96 100644 --- a/lbup/_mountinfo.py +++ b/lbup/_mountinfo.py @@ -15,6 +15,12 @@ def _oct_unescape(b): return b +class NotAbsRoot(Exception): + # This exception is raised for mount entries whose root is not + # a valid absolute path (this happens e.g. for persistent namespaces bound + # to a file). Such entries are skipped from MountInfo + pass + class _MountEntry: "mount ID, bytes" mount_id = None @@ -56,7 +62,10 @@ class _MountEntry: raise ValueError('Invalid device number', devnum) self.devnum = (major << 8) + minor - self.root = AbsPath(_oct_unescape(root)) + root = _oct_unescape(root) + if len(root) < 1 or not root.startswith(b'/'): + raise NotAbsRoot() + self.root = AbsPath(root) self.mount_point = AbsPath(_oct_unescape(mount_point)) self.mount_opts = mount_opts @@ -94,7 +103,10 @@ class MountInfo: def __init__(self, data): self.entries = [] for line in data.splitlines(): - self.entries.append(_MountEntry(line)) + try: + self.entries.append(_MountEntry(line)) + except NotAbsRoot: + pass def __str__(self): return '%s(%d entries)' % (self.__class__.__name__, len(self.entries)) -- cgit v1.2.3