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

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