RuntimeError: dictionary keys changed during iteration (with --json, and Python 3.8)
See original GitHub issueRunning with -j
or --json
with Python 3.8.x cause the following error
± ./ssh-audit.py -j raspberrypi2.local
Traceback (most recent call last):
File "./ssh-audit.py", line 3350, in <module>
main()
File "./ssh-audit.py", line 3347, in main
audit(conf)
File "./ssh-audit.py", line 3337, in audit
print(json.dumps(build_struct(banner, kex=kex, client_host=s.client_host), sort_keys=True))
File "./ssh-audit.py", line 3245, in build_struct
for host_key_type in host_keys.keys():
RuntimeError: dictionary keys changed during iteration
The code in question is
The fix for the immediate is straightforward, replace host_keys.keys()
with list(host_keys.keys())
so the loop iterates over a copy.
However, I’m concerned about the rest of the loop. I think its
- picking one rsa host key amongst (possibly) several, and discarding any others
- the key it keeps is not predictable, because iteration over dict keys is non-deterministic in Python 3.5 and earlier.
I need to confirm whether an ssh server can have multiple RSA keys (perhaps with different key lengths).
Other details
± python3 --version
Python 3.8.2
± git show --summary | cat
commit e447c42a79df49841d5269eacde6dbeb811a6be4
Author: Joe Testa <jtesta@positronsecurity.com>
Date: Wed Mar 11 11:55:14 2020 -0400
Bumped version to v2.2.0.
Issue Analytics
- State:
- Created 3 years ago
- Comments:6 (3 by maintainers)
Top Results From Across the Web
dictionary changed size during iteration" error? - Stack Overflow
The Python "RuntimeError: dictionary changed size during iteration" occurs when we change the size of a dictionary when iterating over it. · To...
Read more >RuntimeError: dictionary changed size during iteration
The Python "RuntimeError: dictionary changed size during iteration" occurs when we change the size of a dictionary when iterating over it.
Read more >Filtering Dictionary In Python 3. “RuntimeError - codeburst
“RuntimeError: Dictionary changed size during iteration”, Python slaps you in your face when you try to add/remove entries in dict object during iteration....
Read more >“RuntimeError: dictionary keys changed during iter...
I am attempting to just add a CSV file to my issues as a test, but I keep receiving the error: ``` RuntimeError:...
Read more >Fix Error - Dictionary Changed Size During Iteration | Delft Stack
This Runtime error occurs when we remove, modify, or add new entries in a dictionary object during iteration. This error occurs when iterating...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Do you have any thoughts on the other possible bug? That if an SSH server offered multiple RSA keys, ssh-audit would pick one at random.
Well enough. I’d more-or-less concluded that multiple RSA keys might be possible according to the protocol, but rarely (if ever) seen in the wild
No, thank you. Close this or leave it open however you prefer.