Skip to content
This repository was archived by the owner on Dec 19, 2023. It is now read-only.

Commit cadfa06

Browse files
committed
Open stdout and stderr as text streams
Nmap stdout and sterr is being used as str. This opens the streams as text, so read()/readline() returns a str instead of a byte, avoiding the need to manually decode from str to byte on each read(). This fixes savon-noir#63 which is an endless loop caused by enumerate() waiting for a '' as sentinel but receiving a b''. Also, NmapProcess.__process_event() expects stderr as str, using a byte breaks it, which in turn breaks NmapProcess.run_background() and NmapProcess.sudo_run_background()
1 parent 00ccad5 commit cadfa06

1 file changed

Lines changed: 3 additions & 2 deletions

File tree

libnmap/process.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,7 @@ def run(self):
259259
self.__nmap_proc = subprocess.Popen(args=_tmp_cmdline,
260260
stdout=subprocess.PIPE,
261261
stderr=subprocess.PIPE,
262+
universal_newlines=True,
262263
bufsize=0)
263264
self.__state = self.RUNNING
264265
except OSError:
@@ -268,12 +269,12 @@ def run(self):
268269

269270
while self.__nmap_proc.poll() is None:
270271
for streamline in iter(self.__nmap_proc.stdout.readline, ''):
271-
self.__stdout += str(streamline)
272+
self.__stdout += streamline
272273
evnt = self.__process_event(streamline)
273274
if self.__nmap_event_callback and evnt:
274275
self.__nmap_event_callback(self)
275276

276-
self.__stderr += str(self.__nmap_proc.stderr.read().decode())
277+
self.__stderr += self.__nmap_proc.stderr.read()
277278

278279
self.__nmap_rc = self.__nmap_proc.poll()
279280
if self.rc is None:

0 commit comments

Comments
 (0)