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

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