Browse Source

Libvlc: patches to fix TLS errors

merge-requests/61/head
Geoffrey Métais 7 years ago
parent
commit
08d512a255
  1. 81
      libvlc/patches/0002-compat-Workaround-sendmsg-bug-on-android.patch
  2. 39
      libvlc/patches/0003-network-tls-Handle-errors-from-older-kernels.patch

81
libvlc/patches/0002-compat-Workaround-sendmsg-bug-on-android.patch

@ -0,0 +1,81 @@
From a9bf3d0db32407b7320269e33a4864e2977badaf Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Hugo=20Beauz=C3=A9e-Luyssen?= <hugo@beauzee.fr>
Date: Thu, 28 Mar 2019 15:23:48 +0100
Subject: [PATCH 1/2] compat: Workaround sendmsg bug on android
This only happens on 64bits builds, see compat/sendmsg.c comments
---
compat/sendmsg.c | 24 ++++++++++++++++++++++++
configure.ac | 3 +++
include/vlc_network.h | 6 ++++++
3 files changed, 33 insertions(+)
diff --git a/compat/sendmsg.c b/compat/sendmsg.c
index 0f42e782f8..8d69048746 100644
--- a/compat/sendmsg.c
+++ b/compat/sendmsg.c
@@ -129,6 +129,30 @@ ssize_t sendmsg(int fd, const struct msghdr *msg, int flags)
free(data);
return res;
}
+#elif defined(__ANDROID__) && defined(__aarch64__)
+
+#undef sendmsg
+
+#include <sys/types.h>
+#include <sys/socket.h>
+
+/**
+ * Since we bumped the NDK version from 14 to 18, some devices (at least up to
+ * Android 6) are returning errors on 4 bytes, even though ssize_t is actually
+ * 8 bytes. This causes `value < 0` checks to yield false, and consider the value
+ * as a non error.
+ * As the patch lies in either the NDK or the Android kernel, or the device libc
+ * we can only work around it. If errno is not 0 & we receive -1, on 32bits or
+ * 64bits, we assume an error was returned.
+ */
+ssize_t vlc_sendmsg(int fd, const struct msghdr *msg, int flags)
+{
+ errno = 0;
+ ssize_t ret = sendmsg(fd, msg, flags);
+ if ((ret < 0 || ret == 0xFFFFFFFF) && errno != 0)
+ return -1;
+ return ret;
+}
#else
#error sendmsg not implemented on your platform!
diff --git a/configure.ac b/configure.ac
index 49b1166742..6f1edd73a3 100644
--- a/configure.ac
+++ b/configure.ac
@@ -365,6 +365,9 @@ AS_IF([test "$SYS" = linux],[
],[
HAVE_ANDROID="1"
AC_MSG_RESULT([yes])
+ AS_IF([test "${host_cpu}" = "aarch64"], [
+ AC_LIBOBJ([sendmsg])
+ ])
],[
AC_MSG_RESULT([no])
])
diff --git a/include/vlc_network.h b/include/vlc_network.h
index 184c23acae..6a43fd7d8b 100644
--- a/include/vlc_network.h
+++ b/include/vlc_network.h
@@ -290,6 +290,12 @@ static inline void net_SetPort (struct sockaddr *addr, uint16_t port)
VLC_API char *vlc_getProxyUrl(const char *);
+#if defined(__ANDROID__) && defined(__aarch64__)
+struct msghdr;
+ssize_t vlc_sendmsg(int fd, const struct msghdr *msg, int flags);
+#define sendmsg(a, b, c) vlc_sendmsg(a,b,c)
+#endif
+
# ifdef __cplusplus
}
# endif
--
2.20.1

39
libvlc/patches/0003-network-tls-Handle-errors-from-older-kernels.patch

@ -0,0 +1,39 @@
From 22f9fa0c66b78096af08a8f51869bbb24a3768e4 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Hugo=20Beauz=C3=A9e-Luyssen?= <hugo@beauzee.fr>
Date: Fri, 29 Mar 2019 10:56:26 +0100
Subject: [PATCH 2/2] network: tls: Handle errors from older kernels
If MSG_FASTOPEN is defined, but turns out to be unimplemented by the
underlying kernel (as is the case on android where the NDK claims to
support fast open but some older kernels don't) EPIPE is returned
instead of EOPNOTSUPP.
See net/ipv4/tcp.c:936 & net/core/stream.c:55
sk_stream_wait_connect will return EPIPE if no SYN was sent/received,
and sendmsg will propagate that error.
Treating EPIPE as a synonym for EOPNOTSUPP here allows for the
connection to proceed, and the first call to sendmsg to complete as
expected.
---
src/network/tls.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/src/network/tls.c b/src/network/tls.c
index 56e04d6ce7..3c3c083c30 100644
--- a/src/network/tls.c
+++ b/src/network/tls.c
@@ -546,8 +546,11 @@ static ssize_t vlc_tls_ConnectWrite(vlc_tls_t *tls,
return -1;
}
else
- if (errno != EOPNOTSUPP)
+ if (errno != EOPNOTSUPP && errno != EPIPE)
+ { /* If MSG_FASTOPEN was defined but the kernel doesn't support fast open at
+ all, EPIPE will be returned instead of EOPNOTSUPP */
return -1;
+ }
/* Fast open not supported or disabled... fallback to normal mode */
#else
tls->writev = vlc_tls_SocketWrite;
--
2.20.1
Loading…
Cancel
Save