summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnton Khirnov <anton@khirnov.net>2020-10-18 17:28:57 +0200
committerAnton Khirnov <anton@khirnov.net>2020-10-18 17:28:57 +0200
commit5997aca7ceeb25b5434afd164e11a4b7d01d222e (patch)
treed8d7d87852356c8d0bc13c12e427535885b3009e
parenta1d73439da9535a006f8df6238254db6d6aad107 (diff)
_mountinfo: skip mount entires with non-absolute root
-rw-r--r--lbup/_mountinfo.py16
1 files 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))