Skip to content

Commit

Permalink
Merge pull request #374 from doronz88/bugfix/gethostbyname
Browse files Browse the repository at this point in the history
client: network: fix handling of bad records in `gethostbyname()`
  • Loading branch information
doronz88 authored Oct 29, 2024
2 parents 95733f0 + 0b82c89 commit aedb281
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 5 deletions.
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ repos:
hooks:
- id: isort
args: [ '-m', 'HANGING_INDENT', '-l', '120','--check-only' ]
files: src/client
files: src/rpcclient

- repo: https://github.com/pycqa/flake8
rev: "7.0.0"
hooks:
- id: flake8
args: [ '--max-line-length=127' ]
files: src/client
files: src/rpcclient
10 changes: 7 additions & 3 deletions src/rpcclient/rpcclient/network.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import socket as pysock
import typing
from collections import namedtuple
from typing import Optional

from rpcclient.allocated import Allocated
from rpcclient.darwin.structs import timeval
Expand Down Expand Up @@ -165,11 +166,14 @@ def unix_connect(self, filename: str) -> Socket:
self._client.raise_errno_exception(f'failed connecting to: {filename}')
return Socket(self._client, sockfd)

def gethostbyname(self, name: str) -> Hostentry:
def gethostbyname(self, name: str) -> Optional[Hostentry]:
""" Query DNS record. Returns None if not found. """
aliases = []
addresses = []

result = hostent(self._client).parse_stream(self._client.symbols.gethostbyname(name))
result = self._client.symbols.gethostbyname(name)
if result == 0:
return None
result = hostent(self._client).parse_stream(result)
p_aliases = result.h_aliases

i = 0
Expand Down
12 changes: 12 additions & 0 deletions src/rpcclient/tests/test_network.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
def test_valid_gethostbyname(client):
"""
:param rpcclient.client.Client client:
"""
assert client.network.gethostbyname('google.com') is not None


def test_invalid_gethostbyname(client):
"""
:param rpcclient.client.Client client:
"""
assert client.network.gethostbyname('google.com1') is None

0 comments on commit aedb281

Please sign in to comment.