Blame SOURCES/0042-sockaddr-properly-decode-sockaddr_hci-addresses-with.patch

35b686
From 5a9b0f1ef83300f853e77ada03515c8542c1cfe0 Mon Sep 17 00:00:00 2001
35b686
From: Eugene Syromyatnikov <evgsyr@gmail.com>
35b686
Date: Thu, 29 Aug 2019 19:03:51 +0200
35b686
Subject: [PATCH] sockaddr: properly decode sockaddr_hci addresses without
35b686
 hci_channel
35b686
35b686
Before Linux commit v2.6.38-rc1~476^2~14^2~3^2~43^2~9,
35b686
struct sockaddr_hci did not contain hci_channel field.
35b686
35b686
* configure.ac (AC_CHECK_HEADERS([bluetooth/bluetooth.h])): Add check
35b686
for struct sockaddr_hci.hci_channel.
35b686
* sockaddr.c (print_sockaddr_data_bt): Decode struct sockaddr_hci
35b686
without hci_channel field.
35b686
* tests/net-sockaddr.c (check_hci): Add check for struct sockaddr_hci
35b686
decoding without hci_channel field; guard hci_channel with #ifdef
35b686
HAVE_STRUCT_SOCKADDR_HCI_HCI_CHANNEL.
35b686
(check_raw): Remove "len++", as 4-byte AF_BLUETOOTH socket addresses are
35b686
interpreted as struct sockaddr_hci without hci_channel field.
35b686
---
35b686
 configure.ac         |  3 +++
35b686
 sockaddr.c           | 16 +++++++++++++---
35b686
 tests/net-sockaddr.c | 18 ++++++++++++++----
35b686
 3 files changed, 30 insertions(+), 7 deletions(-)
35b686
35b686
Index: strace-5.1/configure.ac
35b686
===================================================================
35b686
--- strace-5.1.orig/configure.ac	2019-08-29 19:10:22.380362280 +0200
35b686
+++ strace-5.1/configure.ac	2019-08-29 19:11:11.240744864 +0200
35b686
@@ -465,6 +465,9 @@
35b686
 ])
35b686
 
35b686
 AC_CHECK_HEADERS([bluetooth/bluetooth.h], [
35b686
+	AC_CHECK_MEMBERS([struct sockaddr_hci.hci_channel],,,
35b686
+			 [#include <bluetooth/bluetooth.h>
35b686
+			 #include <bluetooth/hci.h>])
35b686
 	AC_CHECK_MEMBERS([struct sockaddr_l2.l2_bdaddr_type],,,
35b686
 			 [#include <bluetooth/bluetooth.h>
35b686
 			 #include <bluetooth/l2cap.h>])
35b686
Index: strace-5.1/sockaddr.c
35b686
===================================================================
35b686
--- strace-5.1.orig/sockaddr.c	2019-08-29 19:11:11.240744864 +0200
35b686
+++ strace-5.1/sockaddr.c	2019-08-29 19:13:01.275354429 +0200
35b686
@@ -599,12 +599,21 @@
35b686
 	};
35b686
 
35b686
 	switch (addrlen) {
35b686
+	case offsetofend(struct sockaddr_hci, hci_dev):
35b686
 	case sizeof(struct sockaddr_hci): {
35b686
 		const struct sockaddr_hci *const hci = buf;
35b686
-		tprintf("hci_dev=htobs(%hu), hci_channel=",
35b686
-			btohs(hci->hci_dev));
35b686
-		printxval_index(hci_channels, hci->hci_channel,
35b686
-				"HCI_CHANNEL_???");
35b686
+		tprintf("hci_dev=htobs(%hu)", btohs(hci->hci_dev));
35b686
+
35b686
+		/*
35b686
+		 * hci_channel field has been introduced
35b686
+		 * Linux commit in v2.6.38-rc1~476^2~14^2~3^2~43^2~9.
35b686
+		 */
35b686
+		if (addrlen == sizeof(struct sockaddr_hci)) {
35b686
+			tprints(", hci_channel=");
35b686
+			printxval_index(hci_channels, hci->hci_channel,
35b686
+					"HCI_CHANNEL_???");
35b686
+		}
35b686
+
35b686
 		break;
35b686
 	}
35b686
 	case sizeof(struct sockaddr_sco): {
35b686
Index: strace-5.1/tests/net-sockaddr.c
35b686
===================================================================
35b686
--- strace-5.1.orig/tests/net-sockaddr.c	2019-08-29 19:10:22.380362280 +0200
35b686
+++ strace-5.1/tests/net-sockaddr.c	2019-08-29 19:11:11.240744864 +0200
35b686
@@ -543,11 +543,22 @@
35b686
 	TAIL_ALLOC_OBJECT_VAR_PTR(struct sockaddr_hci, hci);
35b686
 	hci->hci_family = AF_BLUETOOTH;
35b686
 	hci->hci_dev = htobs(h_port);
35b686
+# ifdef HAVE_STRUCT_SOCKADDR_HCI_HCI_CHANNEL
35b686
 	hci->hci_channel = HCI_CHANNEL_RAW;
35b686
+# endif
35b686
 	unsigned int len = sizeof(*hci);
35b686
-	int ret = connect(-1, (void *) hci, len);
35b686
+
35b686
+	int ret = connect(-1, (void *) hci, 4);
35b686
+	printf("connect(-1, {sa_family=AF_BLUETOOTH, hci_dev=htobs(%hu)"
35b686
+	       "}, 4) = %d EBADF (%m)\n",
35b686
+	       h_port, ret);
35b686
+
35b686
+	ret = connect(-1, (void *) hci, len);
35b686
 	printf("connect(-1, {sa_family=AF_BLUETOOTH, hci_dev=htobs(%hu)"
35b686
-	       ", hci_channel=HCI_CHANNEL_RAW}, %u) = %d EBADF (%m)\n",
35b686
+# ifdef HAVE_STRUCT_SOCKADDR_HCI_HCI_CHANNEL
35b686
+	       ", hci_channel=HCI_CHANNEL_RAW"
35b686
+# endif
35b686
+	       "}, %u) = %d EBADF (%m)\n",
35b686
 	       h_port, len, ret);
35b686
 }
35b686
 
35b686
@@ -700,9 +711,8 @@
35b686
 	       " = %d EBADF (%m)\n", len, ret);
35b686
 
35b686
 	u.sa->sa_family = AF_BLUETOOTH;
35b686
-	++len;
35b686
 	ret = connect(-1, (void *) u.st, len);
35b686
-	printf("connect(-1, {sa_family=AF_BLUETOOTH, sa_data=\"00\"}, %u)"
35b686
+	printf("connect(-1, {sa_family=AF_BLUETOOTH, sa_data=\"0\"}, %u)"
35b686
 	       " = %d EBADF (%m)\n", len, ret);
35b686
 }
35b686
 
35b686
Index: strace-5.1/tests-m32/net-sockaddr.c
35b686
===================================================================
35b686
--- strace-5.1.orig/tests-m32/net-sockaddr.c	2019-03-18 03:40:16.000000000 +0100
35b686
+++ strace-5.1/tests-m32/net-sockaddr.c	2019-08-29 19:16:28.327738043 +0200
35b686
@@ -543,11 +543,22 @@
35b686
 	TAIL_ALLOC_OBJECT_VAR_PTR(struct sockaddr_hci, hci);
35b686
 	hci->hci_family = AF_BLUETOOTH;
35b686
 	hci->hci_dev = htobs(h_port);
35b686
+# ifdef HAVE_STRUCT_SOCKADDR_HCI_HCI_CHANNEL
35b686
 	hci->hci_channel = HCI_CHANNEL_RAW;
35b686
+# endif
35b686
 	unsigned int len = sizeof(*hci);
35b686
-	int ret = connect(-1, (void *) hci, len);
35b686
+
35b686
+	int ret = connect(-1, (void *) hci, 4);
35b686
+	printf("connect(-1, {sa_family=AF_BLUETOOTH, hci_dev=htobs(%hu)"
35b686
+	       "}, 4) = %d EBADF (%m)\n",
35b686
+	       h_port, ret);
35b686
+
35b686
+	ret = connect(-1, (void *) hci, len);
35b686
 	printf("connect(-1, {sa_family=AF_BLUETOOTH, hci_dev=htobs(%hu)"
35b686
-	       ", hci_channel=HCI_CHANNEL_RAW}, %u) = %d EBADF (%m)\n",
35b686
+# ifdef HAVE_STRUCT_SOCKADDR_HCI_HCI_CHANNEL
35b686
+	       ", hci_channel=HCI_CHANNEL_RAW"
35b686
+# endif
35b686
+	       "}, %u) = %d EBADF (%m)\n",
35b686
 	       h_port, len, ret);
35b686
 }
35b686
 
35b686
@@ -700,9 +711,8 @@
35b686
 	       " = %d EBADF (%m)\n", len, ret);
35b686
 
35b686
 	u.sa->sa_family = AF_BLUETOOTH;
35b686
-	++len;
35b686
 	ret = connect(-1, (void *) u.st, len);
35b686
-	printf("connect(-1, {sa_family=AF_BLUETOOTH, sa_data=\"00\"}, %u)"
35b686
+	printf("connect(-1, {sa_family=AF_BLUETOOTH, sa_data=\"0\"}, %u)"
35b686
 	       " = %d EBADF (%m)\n", len, ret);
35b686
 }
35b686
 
35b686
Index: strace-5.1/tests-mx32/net-sockaddr.c
35b686
===================================================================
35b686
--- strace-5.1.orig/tests-mx32/net-sockaddr.c	2019-03-18 03:40:16.000000000 +0100
35b686
+++ strace-5.1/tests-mx32/net-sockaddr.c	2019-08-29 19:16:30.805706731 +0200
35b686
@@ -543,11 +543,22 @@
35b686
 	TAIL_ALLOC_OBJECT_VAR_PTR(struct sockaddr_hci, hci);
35b686
 	hci->hci_family = AF_BLUETOOTH;
35b686
 	hci->hci_dev = htobs(h_port);
35b686
+# ifdef HAVE_STRUCT_SOCKADDR_HCI_HCI_CHANNEL
35b686
 	hci->hci_channel = HCI_CHANNEL_RAW;
35b686
+# endif
35b686
 	unsigned int len = sizeof(*hci);
35b686
-	int ret = connect(-1, (void *) hci, len);
35b686
+
35b686
+	int ret = connect(-1, (void *) hci, 4);
35b686
+	printf("connect(-1, {sa_family=AF_BLUETOOTH, hci_dev=htobs(%hu)"
35b686
+	       "}, 4) = %d EBADF (%m)\n",
35b686
+	       h_port, ret);
35b686
+
35b686
+	ret = connect(-1, (void *) hci, len);
35b686
 	printf("connect(-1, {sa_family=AF_BLUETOOTH, hci_dev=htobs(%hu)"
35b686
-	       ", hci_channel=HCI_CHANNEL_RAW}, %u) = %d EBADF (%m)\n",
35b686
+# ifdef HAVE_STRUCT_SOCKADDR_HCI_HCI_CHANNEL
35b686
+	       ", hci_channel=HCI_CHANNEL_RAW"
35b686
+# endif
35b686
+	       "}, %u) = %d EBADF (%m)\n",
35b686
 	       h_port, len, ret);
35b686
 }
35b686
 
35b686
@@ -700,9 +711,8 @@
35b686
 	       " = %d EBADF (%m)\n", len, ret);
35b686
 
35b686
 	u.sa->sa_family = AF_BLUETOOTH;
35b686
-	++len;
35b686
 	ret = connect(-1, (void *) u.st, len);
35b686
-	printf("connect(-1, {sa_family=AF_BLUETOOTH, sa_data=\"00\"}, %u)"
35b686
+	printf("connect(-1, {sa_family=AF_BLUETOOTH, sa_data=\"0\"}, %u)"
35b686
 	       " = %d EBADF (%m)\n", len, ret);
35b686
 }
35b686
 
35b686
Index: strace-5.1/configure
35b686
===================================================================
35b686
--- strace-5.1.orig/configure	2019-08-30 17:41:22.748513960 +0200
35b686
+++ strace-5.1/configure	2019-08-30 17:41:43.118251704 +0200
35b686
@@ -12037,6 +12037,18 @@
35b686
 #define HAVE_BLUETOOTH_BLUETOOTH_H 1
35b686
 _ACEOF
35b686
 
35b686
+	ac_fn_c_check_member "$LINENO" "struct sockaddr_hci" "hci_channel" "ac_cv_member_struct_sockaddr_hci_hci_channel" "#include <bluetooth/bluetooth.h>
35b686
+			 #include <bluetooth/hci.h>
35b686
+"
35b686
+if test "x$ac_cv_member_struct_sockaddr_hci_hci_channel" = xyes; then :
35b686
+
35b686
+cat >>confdefs.h <<_ACEOF
35b686
+#define HAVE_STRUCT_SOCKADDR_HCI_HCI_CHANNEL 1
35b686
+_ACEOF
35b686
+
35b686
+
35b686
+fi
35b686
+
35b686
 	ac_fn_c_check_member "$LINENO" "struct sockaddr_l2" "l2_bdaddr_type" "ac_cv_member_struct_sockaddr_l2_l2_bdaddr_type" "#include <bluetooth/bluetooth.h>
35b686
 			 #include <bluetooth/l2cap.h>
35b686
 "
35b686
Index: strace-5.1/config.h.in
35b686
===================================================================
35b686
--- strace-5.1.orig/config.h.in	2019-05-22 15:08:39.000000000 +0200
35b686
+++ strace-5.1/config.h.in	2019-08-30 18:32:25.431500194 +0200
35b686
@@ -1391,6 +1391,9 @@
35b686
 /* Define to 1 if the system has the type `struct sigcontext'. */
35b686
 #undef HAVE_STRUCT_SIGCONTEXT
35b686
 
35b686
+/* Define to 1 if `hci_channel' is a member of `struct sockaddr_hci'. */
35b686
+#undef HAVE_STRUCT_SOCKADDR_HCI_HCI_CHANNEL
35b686
+
35b686
 /* Define to 1 if `l2_bdaddr_type' is a member of `struct sockaddr_l2'. */
35b686
 #undef HAVE_STRUCT_SOCKADDR_L2_L2_BDADDR_TYPE
35b686