Merge branch '1175/fix-break-on-german-system-lang' into develop

PR #1403
This commit is contained in:
Mike Salvatore 2021-08-20 10:37:29 -04:00
commit 434246f21f
2 changed files with 13 additions and 2 deletions

View File

@ -11,6 +11,8 @@ Changelog](https://keepachangelog.com/en/1.0.0/).
pages. #1353 pages. #1353
- Credentials shown in plain text on configuration screens. #1183 - Credentials shown in plain text on configuration screens. #1183
- Typo "trough" -> "through" in telemetry and docstring. - Typo "trough" -> "through" in telemetry and docstring.
- Crash when unexpected character encoding is used by ping command on German
language systems. #1175
## [1.11.0] - 2021-08-13 ## [1.11.0] - 2021-08-13
### Added ### Added

View File

@ -38,18 +38,27 @@ class PingScanner(HostScanner, HostFinger):
) )
def get_host_fingerprint(self, host): def get_host_fingerprint(self, host):
timeout = self._config.ping_scan_timeout timeout = self._config.ping_scan_timeout
if not "win32" == sys.platform: if not "win32" == sys.platform:
timeout /= 1000 timeout /= 1000
ping_cmd = ["ping", PING_COUNT_FLAG, "1", PING_TIMEOUT_FLAG, str(timeout), host.ip_addr]
LOG.debug(f"Running ping command: {' '.join(ping_cmd)}")
# If stdout is not connected to a terminal (i.e. redirected to a pipe or file), the result
# of os.device_encoding(1) will be None. Setting errors="backslashreplace" prevents a crash
# in this case. See #1175 and #1403 for more information.
encoding = os.device_encoding(1)
sub_proc = subprocess.Popen( sub_proc = subprocess.Popen(
["ping", PING_COUNT_FLAG, "1", PING_TIMEOUT_FLAG, str(timeout), host.ip_addr], ping_cmd,
stdout=subprocess.PIPE, stdout=subprocess.PIPE,
stderr=subprocess.PIPE, stderr=subprocess.PIPE,
text=True, text=True,
encoding=encoding,
errors="backslashreplace",
) )
LOG.debug(f"Retrieving ping command output using {encoding} encoding")
output = " ".join(sub_proc.communicate()) output = " ".join(sub_proc.communicate())
regex_result = self._ttl_regex.search(output) regex_result = self._ttl_regex.search(output)
if regex_result: if regex_result: