fox-it / dissect.target

The Dissect module tying all other Dissect modules together. It provides a programming API and command line tools which allow easy access to various data sources inside disk images or file collections (a.k.a. targets).
GNU Affero General Public License v3.0
43 stars 44 forks source link

Fix NoneType AttributeError in firefox extension plugin #713

Closed M1ra1B0T closed 2 months ago

M1ra1B0T commented 4 months ago

This PR fixes a NoneType AttributeError in the firefox extension plugin. When parsing the firefox extension information from the json file, we use the dictionary get method to access the relevant key value pairs. However, I ran into an uncatched NoneType AttributeError if the original key value is None, but we expect a nested dictionary, e.g. for the "name" field.

Additionally, the error message was slightly adapted, so instead of logging the whole user object, it now only prints the username as it should.

Schamper commented 2 months ago

Do you have some test data or could you add some data to the unit test for this? Maybe I'm missing something but on first glance the previous code should be functionality identical?

In [1]: extension = {}

In [2]: repr(extension.get("defaultLocale", {}).get("name"))
Out[2]: 'None'

In [3]: extension = {"defaultLocale": {}}

In [4]: repr(extension.get("defaultLocale", {}).get("name"))
Out[4]: 'None'
M1ra1B0T commented 2 months ago

@Schamper The error occurs if the field defaultLocale is actually None or null

>>> extension = {"defaultLocale": None}
>>> repr(extension.get("defaultLocale", {}).get("name"))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'NoneType' object has no attribute 'get'
codecov[bot] commented 2 months ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Project coverage is 75.05%. Comparing base (f999b3a) to head (40fee57).

Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #713 +/- ## ======================================= Coverage 75.05% 75.05% ======================================= Files 295 295 Lines 25084 25084 ======================================= Hits 18827 18827 Misses 6257 6257 ``` | [Flag](https://app.codecov.io/gh/fox-it/dissect.target/pull/713/flags?src=pr&el=flags&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=fox-it) | Coverage Δ | | |---|---|---| | [unittests](https://app.codecov.io/gh/fox-it/dissect.target/pull/713/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=fox-it) | `75.05% <ø> (ø)` | | Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=fox-it#carryforward-flags-in-the-pull-request-comment) to find out more.

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

Schamper commented 2 months ago

Thanks! Was actually running into this issue too while working on another feature.