-
Notifications
You must be signed in to change notification settings - Fork 480
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add missing exception handling in paths related to cached files and i… #1516
Open
atcuno
wants to merge
2
commits into
develop
Choose a base branch
from
cached_files_exception_handling
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+44
−10
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1070,14 +1070,28 @@ def path(self) -> str: | |
not current_dentry.is_root() | ||
and current_dentry.vol.offset not in dentry_seen | ||
): | ||
parent = current_dentry.d_parent | ||
reversed_path.append(current_dentry.d_name.name_as_str()) | ||
try: | ||
parent = current_dentry.d_parent | ||
except exceptions.InvalidAddressException: | ||
# Gus - is this right? | ||
break | ||
|
||
try: | ||
reversed_path.append(current_dentry.d_name.name_as_str()) | ||
except exceptions.InvalidAddressException: | ||
break | ||
|
||
dentry_seen.add(current_dentry.vol.offset) | ||
current_dentry = parent | ||
|
||
return "/" + "/".join(reversed(reversed_path)) | ||
|
||
def is_root(self) -> bool: | ||
return self.vol.offset == self.d_parent | ||
try: | ||
return self.vol.offset == self.d_parent | ||
except exceptions.InvalidAddressException: | ||
# Gus - I assume False is correct here since d_parent is smeared? | ||
return False | ||
|
||
def is_subdir(self, old_dentry): | ||
"""Is this dentry a subdirectory of old_dentry? | ||
|
@@ -1102,10 +1116,24 @@ def d_ancestor(self, ancestor_dentry): | |
not current_dentry.is_root() | ||
and current_dentry.vol.offset not in dentry_seen | ||
): | ||
if current_dentry.d_parent == ancestor_dentry.vol.offset: | ||
try: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Again, feels like a single try/except could wrap all the statements here because the middle statements don't matter if it's still going to return None on a failure? |
||
parent = current_dentry.d_parent | ||
except exceptions.InvalidAddressException: | ||
# Gus - is None here correct? Should something else be done? | ||
return None | ||
|
||
if parent == ancestor_dentry.vol.offset: | ||
return current_dentry | ||
dentry_seen.add(current_dentry.vol.offset) | ||
current_dentry = current_dentry.d_parent | ||
|
||
try: | ||
parent = current_dentry.d_parent | ||
except exceptions.InvalidAddressException: | ||
# Gus - is None here correct? Should something else be done? | ||
return None | ||
|
||
current_dentry = parent | ||
|
||
return None | ||
|
||
def get_subdirs(self) -> Iterable[interfaces.objects.ObjectInterface]: | ||
|
@@ -1138,12 +1166,11 @@ def get_subdirs(self) -> Iterable[interfaces.objects.ObjectInterface]: | |
def get_inode(self) -> interfaces.objects.ObjectInterface: | ||
"""Returns the inode associated with this dentry""" | ||
|
||
inode_ptr = self.d_inode | ||
if not (inode_ptr and inode_ptr.is_readable() and inode_ptr.is_valid()): | ||
try: | ||
return self.d_inode.dereference() | ||
except exceptions.InvalidAddressException: | ||
return None | ||
|
||
return inode_ptr.dereference() | ||
|
||
|
||
class struct_file(objects.StructType): | ||
def get_dentry(self) -> interfaces.objects.ObjectInterface: | ||
|
@@ -2487,14 +2514,21 @@ def get_pages(self) -> Iterable[interfaces.objects.ObjectInterface]: | |
""" | ||
if not self.i_size: | ||
return | ||
elif not (self.i_mapping and self.i_mapping.nrpages > 0): | ||
|
||
try: | ||
nrpages = self.i_mapping.nrpages | ||
except exceptions.InvalidAddressException: | ||
return | ||
|
||
if nrpages <= 0: | ||
return | ||
|
||
page_cache = linux.PageCache( | ||
context=self._context, | ||
kernel_module_name="kernel", | ||
page_cache=self.i_mapping.dereference(), | ||
) | ||
|
||
yield from page_cache.get_cached_pages() | ||
|
||
def get_contents(self): | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These statements end in the same result, they should probably be in a single try/except block? The traceback would show which line went on, so this just seems excessive?