Backport fix for crashes when message contains multiple xaddrs

This commit is contained in:
Ondrej Holy 2023-11-07 10:42:59 +01:00
parent b846d353c3
commit c65d2b83f7
2 changed files with 91 additions and 1 deletions

View File

@ -0,0 +1,87 @@
From c4a5f346bbb22777a8f66b0d6c6ef899f6d6cc74 Mon Sep 17 00:00:00 2001
From: Steffen Christgau <mail@s14u.de>
Date: Sun, 14 May 2023 21:47:16 +0200
Subject: [PATCH] fix(src): Handle multiple xaddrs in ResolveMatch/ProbeMatch
Currently, the `ProbeMatch`/`ResolveMatch` messages with multiple
transport addresses cause the `http.client.InvalidURL: URL can't contain
control characters.` exceptions. Those messages seem to be valid and can
be received e.g. from HP printers. Let's use the same approach as it was
implemented for the `Hello` message over the
https://github.com/christgau/wsdd/commit/918a1ae8a3e600366ccdf936bb247a43143f298f
commit to fix this issue.
Related: https://github.com/christgau/wsdd/issues/89
Fixes: https://github.com/christgau/wsdd/issues/149
Co-authored-by: Ondrej Holy <ondrejholy@users.noreply.github.com>
Signed-off-by: Steffen Christgau <mail@s14u.de>
---
src/wsdd.py | 33 ++++++++++++++++++++-------------
1 file changed, 20 insertions(+), 13 deletions(-)
diff --git a/src/wsdd.py b/src/wsdd.py
index 862c6eb..39f54c9 100755
--- a/src/wsdd.py
+++ b/src/wsdd.py
@@ -738,6 +738,17 @@ def teardown(self) -> None:
def handle_packet(self, msg: str, src: Optional[UdpAddress] = None) -> None:
self.handle_message(msg, src)
+ def __extract_xaddr(self, xaddrs: str) -> Optional[str]:
+ for addr in xaddrs.strip().split():
+ if (self.mch.address.family == socket.AF_INET6) and ('//[fe80::' in addr):
+ # use first link-local address for IPv6
+ return addr
+ elif self.mch.address.family == socket.AF_INET:
+ # use first (and very likely the only) IPv4 address
+ return addr
+
+ return None
+
def handle_hello(self, header: ElementTree.Element, body: ElementTree.Element) -> Optional[WSDMessage]:
pm_path = 'wsd:Hello'
endpoint, xaddrs = self.extract_endpoint_metadata(body, pm_path)
@@ -747,17 +758,7 @@ def handle_hello(self, header: ElementTree.Element, body: ElementTree.Element) -
self.enqueue_datagram(msg, self.mch.multicast_address)
return None
- xaddr = None
- for addr in xaddrs.strip().split():
- if (self.mch.address.family == socket.AF_INET6) and ('//[fe80::' in addr):
- # use first link-local address for IPv6
- xaddr = addr
- break
- elif self.mch.address.family == socket.AF_INET:
- # use first (and very likely the only) IPv4 address
- xaddr = addr
- break
-
+ xaddr = self.__extract_xaddr(xaddrs)
if xaddr is None:
return None
@@ -790,7 +791,10 @@ def handle_probe_match(self, header: ElementTree.Element, body: ElementTree.Elem
self.enqueue_datagram(msg, self.mch.multicast_address)
return None
- xaddr = xaddrs.strip()
+ xaddr = self.__extract_xaddr(xaddrs)
+ if xaddr is None:
+ return None
+
logger.debug('probe match for {} on {}'.format(endpoint, xaddr))
self.perform_metadata_exchange(endpoint, xaddr)
@@ -809,7 +813,10 @@ def handle_resolve_match(self, header: ElementTree.Element, body: ElementTree.El
logger.debug('resolve match without endpoint/xaddr')
return None
- xaddr = xaddrs.strip()
+ xaddr = self.__extract_xaddr(xaddrs)
+ if xaddr is None:
+ return None
+
logger.debug('resolve match for {} on {}'.format(endpoint, xaddr))
self.perform_metadata_exchange(endpoint, xaddr)

View File

@ -10,6 +10,9 @@ Source2: wsdd.xml
Source3: wsdd-http.xml
Source4: wsdd.sysconfig
# https://github.com/christgau/wsdd/issues/149
Patch: c4a5f346bbb22777a8f66b0d6c6ef899f6d6cc74.patch
BuildArch: noarch
BuildRequires: systemd
Requires(pre): shadow-utils
@ -22,7 +25,7 @@ like Windows.
%prep
%autosetup
%autosetup -p1
%install