guardicore / monkey

Infection Monkey - An open-source adversary emulation platform
https://www.guardicore.com/infectionmonkey/
GNU General Public License v3.0
6.56k stars 765 forks source link

TypeError: _cast_by_example #109

Closed delirious-lettuce closed 6 years ago

delirious-lettuce commented 6 years ago

Expected Behavior

Not raise a TypeError

Actual Behavior

Raises a TypeError

Steps to Reproduce the Problem

  1. Call _cast_by_example with a value which isn't None and example as a tuple with a minimum length of 1.
>>> _cast_by_example('value', ('example',))
Traceback (most recent call last):
  File "<input>", line 1, in <module>
  File "<input>", line 14, in _cast_by_example
TypeError: 'NoneType' object is not iterable

The problem is in this line:

https://github.com/guardicore/monkey/blob/8f0251e822f937d9ee38bccc982fb50e8a9fcdb2/infection_monkey/config.py#L28

The issue is calling tuple(None):

>>> tuple(None)
Traceback (most recent call last):
  File "<input>", line 1, in <module>
TypeError: 'NoneType' object is not iterable

Potential Fix

The problem line is almost exactly the same as this line (four lines below the problem line):

https://github.com/guardicore/monkey/blob/8f0251e822f937d9ee38bccc982fb50e8a9fcdb2/infection_monkey/config.py#L32

After looking at that, it seems like a potential fix would be either:

if value is None or value == (None,):
# or
if value is None or value == tuple([None]):

Both of these produce a tuple with one element which is None.

>>> (None,)
(None,)
>>> tuple([None])
(None,)

I didn't send a PR since I wasn't exactly sure if this would be correct and if so, which one of these would be preferred.

danielguardicore commented 6 years ago

Hey, Well, that's a bug. I think you're right on the solution. Want to open a one liner PR? 🥇

Also, what did you change in the configuration to run into this bug?

danielguardicore commented 6 years ago

Will be solved in a bugfix soon :)

danielguardicore commented 6 years ago

fixed in #111