We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
free -m command results in stack trace and cowrie freezes
From within cowrie (docker current 7 Dec 2018), when the command "free -m" is run it results a stack trace errors shown below.  Cowrie freezes., and since many bots use free as info gathering, cowry may miss everything subsequent to this command.

Environment:
Ubuntu 16.04
Python 3.5.2
docker pull cowrie/cowrie
sudo iptables -t nat -A PREROUTING -p tcp --dport 22 -j REDIRECT --to-port 2222
docker run -it -p 2222:2222 -p 2223:2223 cowrie/cowrie

Console Error:
2018-12-07T04:53:52+0000 [SSHChannel session (0) on SSHService b'ssh-connection' on HoneyPotSSHTransport,1,172.17.0
.1] CMD: free -m
2018-12-07T04:53:52+0000 [SSHChannel session (0) on SSHService b'ssh-connection' on HoneyPotSSHTransport,1,172.17.0
.1] Command found: free -m
2018-12-07T04:53:52+0000 [SSHChannel session (0) on SSHService b'ssh-connection' on HoneyPotSSHTransport,1,172.17.0
.1] Unhandled Error
        Traceback (most recent call last):
          File "/cowrie/cowrie-env/lib/python3.5/site-packages/twisted/python/context.py", line 122, in callWithCon
text
            return self.currentContext().callWithContext(ctx, func, *args, **kw)
          File "/cowrie/cowrie-env/lib/python3.5/site-packages/twisted/python/context.py", line 85, in callWithCont
ext
            return func(*args,**kw)
          File "/cowrie/cowrie-env/lib/python3.5/site-packages/twisted/conch/ssh/service.py", line 45, in packetRec
eived
            return f(packet)
          File "/cowrie/cowrie-env/lib/python3.5/site-packages/twisted/conch/ssh/connection.py", line 249, in ssh_C
HANNEL_DATA
            log.callWithLogger(channel, channel.dataReceived, data)
        --- <exception caught here> ---
          File "/cowrie/cowrie-env/lib/python3.5/site-packages/twisted/python/log.py", line 103, in callWithLogger
            return callWithContext({"system": lp}, func, *args, **kw)
          File "/cowrie/cowrie-env/lib/python3.5/site-packages/twisted/python/log.py", line 86, in callWithContext
            return context.call({ILogContext: newCtx}, func, *args, **kw)
          File "/cowrie/cowrie-env/lib/python3.5/site-packages/twisted/python/context.py", line 122, in callWithCon
text
            return self.currentContext().callWithContext(ctx, func, *args, **kw)
          File "/cowrie/cowrie-env/lib/python3.5/site-packages/twisted/python/context.py", line 85, in callWithCont
ext
            return func(*args,**kw)
          File "/cowrie/cowrie-env/lib/python3.5/site-packages/twisted/conch/ssh/session.py", line 112, in dataRece
ived
            self.client.transport.write(data)
          File "/cowrie/cowrie-env/lib/python3.5/site-packages/twisted/conch/ssh/session.py", line 163, in write
            self.proto.dataReceived(data)
          File "/cowrie/cowrie-git/src/cowrie/insults/insults.py", line 104, in dataReceived
            insults.ServerProtocol.dataReceived(self, data)
          File "/cowrie/cowrie-env/lib/python3.5/site-packages/twisted/conch/insults/insults.py", line 537, in data
Received
            self.terminalProtocol.keystrokeReceived(ch, None)
          File "/cowrie/cowrie-env/lib/python3.5/site-packages/twisted/conch/recvline.py", line 225, in keystrokeRe
ceived
            m()
          File "/cowrie/cowrie-git/src/cowrie/shell/protocol.py", line 325, in handle_RETURN
            return recvline.RecvLine.handle_RETURN(self)
          File "/cowrie/cowrie-env/lib/python3.5/site-packages/twisted/conch/recvline.py", line 292, in handle_RETU
RN
            self.lineReceived(line)
          File "/cowrie/cowrie-git/src/cowrie/shell/protocol.py", line 185, in lineReceived
            self.cmdstack[-1].lineReceived(line)
          File "/cowrie/cowrie-git/src/cowrie/shell/honeypot.py", line 106, in lineReceived
            self.runCommand()
          File "/cowrie/cowrie-git/src/cowrie/shell/honeypot.py", line 215, in runCommand
            self.protocol.call_command(pp, cmdclass, *cmd_array[0]['rargs'])
          File "/cowrie/cowrie-git/src/cowrie/shell/protocol.py", line 306, in call_command
            HoneyPotBaseProtocol.call_command(self, pp, cmd, *args)
          File "/cowrie/cowrie-git/src/cowrie/shell/protocol.py", line 194, in call_command
            obj.start()
          File "/cowrie/cowrie-git/src/cowrie/shell/command.py", line 128, in start
            self.call()
          File "/cowrie/cowrie-git/src/cowrie/commands/free.py", line 41, in call
            self.do_free(fmt='megabytes')
          File "/cowrie/cowrie-git/src/cowrie/commands/free.py", line 60, in do_free
            for key, value in raw_mem_stats.iteritems():
        builtins.AttributeError: 'dict' object has no attribute 'iteritems'


--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `src/cowrie/commands/free.py`
Content:
```
1 # Copyright (c) 2015 Michel Oosterhof <michel@oosterhof.net>
2 # All rights reserved.
3 
4 """
5 This module ...
6 """
7 
8 from __future__ import absolute_import, division
9 
10 import getopt
11 
12 from cowrie.shell.command import HoneyPotCommand
13 
14 commands = {}
15 
16 FREE_OUTPUT = """              total        used        free      shared  buff/cache   available
17 Mem:{MemTotal:>15}{calc_total_used:>12}{MemFree:>12}{Shmem:>12}{calc_total_buffers_and_cache:>12}{MemAvailable:>12}
18 Swap:{SwapTotal:>14}{calc_swap_used:>12}{SwapFree:>12}
19 """
20 
21 
22 class command_free(HoneyPotCommand):
23     """
24     free
25     """
26 
27     def call(self):
28         # Parse options or display no files
29         try:
30             opts, args = getopt.getopt(self.args, 'mh')
31         except getopt.GetoptError:
32             self.do_free()
33             return
34 
35         # Parse options
36         for o, a in opts:
37             if o in ('-h'):
38                 self.do_free(fmt='human')
39                 return
40             elif o in ('-m'):
41                 self.do_free(fmt='megabytes')
42                 return
43         self.do_free()
44 
45     def do_free(self, fmt='kilobytes'):
46         """
47         print free statistics
48         """
49 
50         # Get real host memstats and add the calculated fields
51         raw_mem_stats = self.get_free_stats()
52         raw_mem_stats['calc_total_buffers_and_cache'] = raw_mem_stats['Buffers'] + raw_mem_stats['Cached']
53         raw_mem_stats['calc_total_used'] = raw_mem_stats['MemTotal'] - (
54             raw_mem_stats['MemFree'] + raw_mem_stats['calc_total_buffers_and_cache']
55         )
56         raw_mem_stats['calc_swap_used'] = raw_mem_stats['SwapTotal'] - raw_mem_stats['SwapFree']
57 
58         if fmt == 'megabytes':
59             # Transform KB to MB
60             for key, value in raw_mem_stats.iteritems():
61                 raw_mem_stats[key] = int(value / 1000)
62         elif fmt == 'human':
63             magnitude = ["B", "M", "G", "T", "Z"]
64             for key, value in raw_mem_stats.iteritems():
65                 current_magnitude = 0
66 
67                 # Keep dividing until we get a sane magnitude
68                 while(value >= 1000 and current_magnitude < len(magnitude)):
69                     value = round(float(value / 1000), 1)
70                     current_magnitude += 1
71 
72                 # Format to string and append value with new magnitude
73                 raw_mem_stats[key] = str("{:g}{}".format(value, magnitude[current_magnitude]))
74 
75         # Write the output to screen
76         self.write(FREE_OUTPUT.format(**raw_mem_stats))
77 
78     def get_free_stats(self):
79         """
80         Get the free stats from /proc
81         """
82         needed_keys = ["Buffers", "Cached", "MemTotal", "MemFree", "SwapTotal", "SwapFree", "Shmem", "MemAvailable"]
83         mem_info_map = {}
84         with open('/proc/meminfo', 'r') as proc_file:
85             for line in proc_file:
86                 tokens = line.split(':')
87 
88                 # Later we are going to do some math on those numbers, better not include uneeded keys for performance
89                 if tokens[0] in needed_keys:
90                     mem_info_map[tokens[0]] = int(tokens[1].lstrip().split(' ')[0])
91 
92         # Got a map with all tokens from /proc/meminfo and sizes in KBs
93         return mem_info_map
94 
95 
96 commands['/usr/bin/free'] = command_free
97 commands['free'] = command_free
98
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/src/cowrie/commands/free.py b/src/cowrie/commands/free.py
--- a/src/cowrie/commands/free.py
+++ b/src/cowrie/commands/free.py
@@ -57,7 +57,7 @@
 
         if fmt == 'megabytes':
             # Transform KB to MB
-            for key, value in raw_mem_stats.iteritems():
+            for key, value in raw_mem_stats.items():
                 raw_mem_stats[key] = int(value / 1000)
         elif fmt == 'human':
             magnitude = ["B", "M", "G", "T", "Z"]

{"golden_diff": "diff --git a/src/cowrie/commands/free.py b/src/cowrie/commands/free.py\n--- a/src/cowrie/commands/free.py\n+++ b/src/cowrie/commands/free.py\n@@ -57,7 +57,7 @@\n \n         if fmt == 'megabytes':\n             # Transform KB to MB\n-            for key, value in raw_mem_stats.iteritems():\n+            for key, value in raw_mem_stats.items():\n                 raw_mem_stats[key] = int(value / 1000)\n         elif fmt == 'human':\n             magnitude = [\"B\", \"M\", \"G\", \"T\", \"Z\"]\n", "issue": "free -m command results in stack trace and cowrie freezes\nFrom within cowrie (docker current 7 Dec 2018), when the command \"free -m\" is run it results a stack trace errors shown below.  Cowrie freezes., and since many bots use free as info gathering, cowry may miss everything subsequent to this command.\r\n\r\nEnvironment:\r\nUbuntu 16.04\r\nPython 3.5.2\r\ndocker pull cowrie/cowrie\r\nsudo iptables -t nat -A PREROUTING -p tcp --dport 22 -j REDIRECT --to-port 2222\r\ndocker run -it -p 2222:2222 -p 2223:2223 cowrie/cowrie\r\n\r\nConsole Error:\r\n2018-12-07T04:53:52+0000 [SSHChannel session (0) on SSHService b'ssh-connection' on HoneyPotSSHTransport,1,172.17.0\r\n.1] CMD: free -m\r\n2018-12-07T04:53:52+0000 [SSHChannel session (0) on SSHService b'ssh-connection' on HoneyPotSSHTransport,1,172.17.0\r\n.1] Command found: free -m\r\n2018-12-07T04:53:52+0000 [SSHChannel session (0) on SSHService b'ssh-connection' on HoneyPotSSHTransport,1,172.17.0\r\n.1] Unhandled Error\r\n        Traceback (most recent call last):\r\n          File \"/cowrie/cowrie-env/lib/python3.5/site-packages/twisted/python/context.py\", line 122, in callWithCon\r\ntext\r\n            return self.currentContext().callWithContext(ctx, func, *args, **kw)\r\n          File \"/cowrie/cowrie-env/lib/python3.5/site-packages/twisted/python/context.py\", line 85, in callWithCont\r\next\r\n            return func(*args,**kw)\r\n          File \"/cowrie/cowrie-env/lib/python3.5/site-packages/twisted/conch/ssh/service.py\", line 45, in packetRec\r\neived\r\n            return f(packet)\r\n          File \"/cowrie/cowrie-env/lib/python3.5/site-packages/twisted/conch/ssh/connection.py\", line 249, in ssh_C\r\nHANNEL_DATA\r\n            log.callWithLogger(channel, channel.dataReceived, data)\r\n        --- <exception caught here> ---\r\n          File \"/cowrie/cowrie-env/lib/python3.5/site-packages/twisted/python/log.py\", line 103, in callWithLogger\r\n            return callWithContext({\"system\": lp}, func, *args, **kw)\r\n          File \"/cowrie/cowrie-env/lib/python3.5/site-packages/twisted/python/log.py\", line 86, in callWithContext\r\n            return context.call({ILogContext: newCtx}, func, *args, **kw)\r\n          File \"/cowrie/cowrie-env/lib/python3.5/site-packages/twisted/python/context.py\", line 122, in callWithCon\r\ntext\r\n            return self.currentContext().callWithContext(ctx, func, *args, **kw)\r\n          File \"/cowrie/cowrie-env/lib/python3.5/site-packages/twisted/python/context.py\", line 85, in callWithCont\r\next\r\n            return func(*args,**kw)\r\n          File \"/cowrie/cowrie-env/lib/python3.5/site-packages/twisted/conch/ssh/session.py\", line 112, in dataRece\r\nived\r\n            self.client.transport.write(data)\r\n          File \"/cowrie/cowrie-env/lib/python3.5/site-packages/twisted/conch/ssh/session.py\", line 163, in write\r\n            self.proto.dataReceived(data)\r\n          File \"/cowrie/cowrie-git/src/cowrie/insults/insults.py\", line 104, in dataReceived\r\n            insults.ServerProtocol.dataReceived(self, data)\r\n          File \"/cowrie/cowrie-env/lib/python3.5/site-packages/twisted/conch/insults/insults.py\", line 537, in data\r\nReceived\r\n            self.terminalProtocol.keystrokeReceived(ch, None)\r\n          File \"/cowrie/cowrie-env/lib/python3.5/site-packages/twisted/conch/recvline.py\", line 225, in keystrokeRe\r\nceived\r\n            m()\r\n          File \"/cowrie/cowrie-git/src/cowrie/shell/protocol.py\", line 325, in handle_RETURN\r\n            return recvline.RecvLine.handle_RETURN(self)\r\n          File \"/cowrie/cowrie-env/lib/python3.5/site-packages/twisted/conch/recvline.py\", line 292, in handle_RETU\r\nRN\r\n            self.lineReceived(line)\r\n          File \"/cowrie/cowrie-git/src/cowrie/shell/protocol.py\", line 185, in lineReceived\r\n            self.cmdstack[-1].lineReceived(line)\r\n          File \"/cowrie/cowrie-git/src/cowrie/shell/honeypot.py\", line 106, in lineReceived\r\n            self.runCommand()\r\n          File \"/cowrie/cowrie-git/src/cowrie/shell/honeypot.py\", line 215, in runCommand\r\n            self.protocol.call_command(pp, cmdclass, *cmd_array[0]['rargs'])\r\n          File \"/cowrie/cowrie-git/src/cowrie/shell/protocol.py\", line 306, in call_command\r\n            HoneyPotBaseProtocol.call_command(self, pp, cmd, *args)\r\n          File \"/cowrie/cowrie-git/src/cowrie/shell/protocol.py\", line 194, in call_command\r\n            obj.start()\r\n          File \"/cowrie/cowrie-git/src/cowrie/shell/command.py\", line 128, in start\r\n            self.call()\r\n          File \"/cowrie/cowrie-git/src/cowrie/commands/free.py\", line 41, in call\r\n            self.do_free(fmt='megabytes')\r\n          File \"/cowrie/cowrie-git/src/cowrie/commands/free.py\", line 60, in do_free\r\n            for key, value in raw_mem_stats.iteritems():\r\n        builtins.AttributeError: 'dict' object has no attribute 'iteritems'\r\n\n", "before_files": [{"content": "# Copyright (c) 2015 Michel Oosterhof <michel@oosterhof.net>\n# All rights reserved.\n\n\"\"\"\nThis module ...\n\"\"\"\n\nfrom __future__ import absolute_import, division\n\nimport getopt\n\nfrom cowrie.shell.command import HoneyPotCommand\n\ncommands = {}\n\nFREE_OUTPUT = \"\"\"              total        used        free      shared  buff/cache   available\nMem:{MemTotal:>15}{calc_total_used:>12}{MemFree:>12}{Shmem:>12}{calc_total_buffers_and_cache:>12}{MemAvailable:>12}\nSwap:{SwapTotal:>14}{calc_swap_used:>12}{SwapFree:>12}\n\"\"\"\n\n\nclass command_free(HoneyPotCommand):\n    \"\"\"\n    free\n    \"\"\"\n\n    def call(self):\n        # Parse options or display no files\n        try:\n            opts, args = getopt.getopt(self.args, 'mh')\n        except getopt.GetoptError:\n            self.do_free()\n            return\n\n        # Parse options\n        for o, a in opts:\n            if o in ('-h'):\n                self.do_free(fmt='human')\n                return\n            elif o in ('-m'):\n                self.do_free(fmt='megabytes')\n                return\n        self.do_free()\n\n    def do_free(self, fmt='kilobytes'):\n        \"\"\"\n        print free statistics\n        \"\"\"\n\n        # Get real host memstats and add the calculated fields\n        raw_mem_stats = self.get_free_stats()\n        raw_mem_stats['calc_total_buffers_and_cache'] = raw_mem_stats['Buffers'] + raw_mem_stats['Cached']\n        raw_mem_stats['calc_total_used'] = raw_mem_stats['MemTotal'] - (\n            raw_mem_stats['MemFree'] + raw_mem_stats['calc_total_buffers_and_cache']\n        )\n        raw_mem_stats['calc_swap_used'] = raw_mem_stats['SwapTotal'] - raw_mem_stats['SwapFree']\n\n        if fmt == 'megabytes':\n            # Transform KB to MB\n            for key, value in raw_mem_stats.iteritems():\n                raw_mem_stats[key] = int(value / 1000)\n        elif fmt == 'human':\n            magnitude = [\"B\", \"M\", \"G\", \"T\", \"Z\"]\n            for key, value in raw_mem_stats.iteritems():\n                current_magnitude = 0\n\n                # Keep dividing until we get a sane magnitude\n                while(value >= 1000 and current_magnitude < len(magnitude)):\n                    value = round(float(value / 1000), 1)\n                    current_magnitude += 1\n\n                # Format to string and append value with new magnitude\n                raw_mem_stats[key] = str(\"{:g}{}\".format(value, magnitude[current_magnitude]))\n\n        # Write the output to screen\n        self.write(FREE_OUTPUT.format(**raw_mem_stats))\n\n    def get_free_stats(self):\n        \"\"\"\n        Get the free stats from /proc\n        \"\"\"\n        needed_keys = [\"Buffers\", \"Cached\", \"MemTotal\", \"MemFree\", \"SwapTotal\", \"SwapFree\", \"Shmem\", \"MemAvailable\"]\n        mem_info_map = {}\n        with open('/proc/meminfo', 'r') as proc_file:\n            for line in proc_file:\n                tokens = line.split(':')\n\n                # Later we are going to do some math on those numbers, better not include uneeded keys for performance\n                if tokens[0] in needed_keys:\n                    mem_info_map[tokens[0]] = int(tokens[1].lstrip().split(' ')[0])\n\n        # Got a map with all tokens from /proc/meminfo and sizes in KBs\n        return mem_info_map\n\n\ncommands['/usr/bin/free'] = command_free\ncommands['free'] = command_free\n", "path": "src/cowrie/commands/free.py"}], "after_files": [{"content": "# Copyright (c) 2015 Michel Oosterhof <michel@oosterhof.net>\n# All rights reserved.\n\n\"\"\"\nThis module ...\n\"\"\"\n\nfrom __future__ import absolute_import, division\n\nimport getopt\n\nfrom cowrie.shell.command import HoneyPotCommand\n\ncommands = {}\n\nFREE_OUTPUT = \"\"\"              total        used        free      shared  buff/cache   available\nMem:{MemTotal:>15}{calc_total_used:>12}{MemFree:>12}{Shmem:>12}{calc_total_buffers_and_cache:>12}{MemAvailable:>12}\nSwap:{SwapTotal:>14}{calc_swap_used:>12}{SwapFree:>12}\n\"\"\"\n\n\nclass command_free(HoneyPotCommand):\n    \"\"\"\n    free\n    \"\"\"\n\n    def call(self):\n        # Parse options or display no files\n        try:\n            opts, args = getopt.getopt(self.args, 'mh')\n        except getopt.GetoptError:\n            self.do_free()\n            return\n\n        # Parse options\n        for o, a in opts:\n            if o in ('-h'):\n                self.do_free(fmt='human')\n                return\n            elif o in ('-m'):\n                self.do_free(fmt='megabytes')\n                return\n        self.do_free()\n\n    def do_free(self, fmt='kilobytes'):\n        \"\"\"\n        print free statistics\n        \"\"\"\n\n        # Get real host memstats and add the calculated fields\n        raw_mem_stats = self.get_free_stats()\n        raw_mem_stats['calc_total_buffers_and_cache'] = raw_mem_stats['Buffers'] + raw_mem_stats['Cached']\n        raw_mem_stats['calc_total_used'] = raw_mem_stats['MemTotal'] - (\n            raw_mem_stats['MemFree'] + raw_mem_stats['calc_total_buffers_and_cache']\n        )\n        raw_mem_stats['calc_swap_used'] = raw_mem_stats['SwapTotal'] - raw_mem_stats['SwapFree']\n\n        if fmt == 'megabytes':\n            # Transform KB to MB\n            for key, value in raw_mem_stats.items():\n                raw_mem_stats[key] = int(value / 1000)\n        elif fmt == 'human':\n            magnitude = [\"B\", \"M\", \"G\", \"T\", \"Z\"]\n            for key, value in raw_mem_stats.iteritems():\n                current_magnitude = 0\n\n                # Keep dividing until we get a sane magnitude\n                while(value >= 1000 and current_magnitude < len(magnitude)):\n                    value = round(float(value / 1000), 1)\n                    current_magnitude += 1\n\n                # Format to string and append value with new magnitude\n                raw_mem_stats[key] = str(\"{:g}{}\".format(value, magnitude[current_magnitude]))\n\n        # Write the output to screen\n        self.write(FREE_OUTPUT.format(**raw_mem_stats))\n\n    def get_free_stats(self):\n        \"\"\"\n        Get the free stats from /proc\n        \"\"\"\n        needed_keys = [\"Buffers\", \"Cached\", \"MemTotal\", \"MemFree\", \"SwapTotal\", \"SwapFree\", \"Shmem\", \"MemAvailable\"]\n        mem_info_map = {}\n        with open('/proc/meminfo', 'r') as proc_file:\n            for line in proc_file:\n                tokens = line.split(':')\n\n                # Later we are going to do some math on those numbers, better not include uneeded keys for performance\n                if tokens[0] in needed_keys:\n                    mem_info_map[tokens[0]] = int(tokens[1].lstrip().split(' ')[0])\n\n        # Got a map with all tokens from /proc/meminfo and sizes in KBs\n        return mem_info_map\n\n\ncommands['/usr/bin/free'] = command_free\ncommands['free'] = command_free\n", "path": "src/cowrie/commands/free.py"}]}