From 426d760b376bb752e4e3bc5312e7ef6eab696519 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Bernhard=20Rosenkr=C3=A4nzer?=
 <bernhard.rosenkraenzer.ext@huawei.com>
Date: Wed, 8 Sep 2021 22:39:59 +0200
Subject: [PATCH] networkmanager: Fix crash on startup with musl
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Fix crash on startup with networkmanager built with musl

Signed-off-by: Bernhard Rosenkränzer <bernhard.rosenkraenzer.ext@huawei.com>
---
 .../fix-strerror_r.patch                      | 34 +++++++++++++++++++
 .../fix-strerror_r.patch.license              |  3 ++
 .../networkmanager_1.22.10.bbappend           |  4 ++-
 3 files changed, 40 insertions(+), 1 deletion(-)
 create mode 100644 meta-ohos-staging/recipes-connectivity/networkmanager/networkmanager-1.22.10/fix-strerror_r.patch
 create mode 100644 meta-ohos-staging/recipes-connectivity/networkmanager/networkmanager-1.22.10/fix-strerror_r.patch.license

diff --git a/meta-ohos-staging/recipes-connectivity/networkmanager/networkmanager-1.22.10/fix-strerror_r.patch b/meta-ohos-staging/recipes-connectivity/networkmanager/networkmanager-1.22.10/fix-strerror_r.patch
new file mode 100644
index 00000000..c284f75e
--- /dev/null
+++ b/meta-ohos-staging/recipes-connectivity/networkmanager/networkmanager-1.22.10/fix-strerror_r.patch
@@ -0,0 +1,34 @@
+From 18765456467af24786bc2397ca72affe42149504 Wed Sep  8 22:33:40 2021
+From: Bernhard Rosenkraenzer <bernhard.rosenkraenzer.ext@huawei.com>
+Date: Wed,  8 Sep 2021 22:33:40 +0200
+Subject: [PATCH] Fix crash on startup when using musl
+
+nm_strerror_native_r makes use of a glibc extension to strerror_r
+when _GNU_SOURCE is defined -- even when not using glibc.
+
+musl uses _GNU_SOURCE for some extensions, but doesn't have the
+strerror_r for unknown error codes extension -- resulting in a
+NULL pointer being passed to UTF-8 check functions that don't
+check for it.
+
+Use the non-glibc code path when __GLIBC__ isn't set.
+
+Signed-off-by: Bernhard Rosenkraenzer <bernhard.rosenkraenzer.ext@huawei.com>
+Upstream-status: Inappropriate [problem doesn't exist in current releases]
+
+---
+ nm-errno.c |    2 +-
+ 1 file changed, 1 insertion(+), 1 deletion(-)
+
+diff -up NetworkManager-1.22.10/shared/nm-glib-aux/nm-errno.c.omv~ NetworkManager-1.22.10/shared/nm-glib-aux/nm-errno.c
+--- NetworkManager-1.22.10/shared/nm-glib-aux/nm-errno.c.omv~	2021-09-08 22:10:10.753007649 +0200
++++ NetworkManager-1.22.10/shared/nm-glib-aux/nm-errno.c	2021-09-08 22:18:11.975338808 +0200
+@@ -106,7 +106,7 @@ nm_strerror_native_r (int errsv, char *b
+ 	nm_assert (buf);
+ 	nm_assert (buf_size > 0);
+ 
+-#if (_POSIX_C_SOURCE >= 200112L) && !  _GNU_SOURCE
++#if !defined(__GLIBC__) || ((_POSIX_C_SOURCE >= 200112L) && !  _GNU_SOURCE)
+ 	/* XSI-compliant */
+ 	{
+ 		int errno_saved = errno;
diff --git a/meta-ohos-staging/recipes-connectivity/networkmanager/networkmanager-1.22.10/fix-strerror_r.patch.license b/meta-ohos-staging/recipes-connectivity/networkmanager/networkmanager-1.22.10/fix-strerror_r.patch.license
new file mode 100644
index 00000000..98a0b3f4
--- /dev/null
+++ b/meta-ohos-staging/recipes-connectivity/networkmanager/networkmanager-1.22.10/fix-strerror_r.patch.license
@@ -0,0 +1,3 @@
+# SPDX-FileCopyrightText: Huawei Inc.
+#
+# SPDX-License-Identifier: Apache-2.0
diff --git a/meta-ohos-staging/recipes-connectivity/networkmanager/networkmanager_1.22.10.bbappend b/meta-ohos-staging/recipes-connectivity/networkmanager/networkmanager_1.22.10.bbappend
index 8baf5c25..346b60e7 100644
--- a/meta-ohos-staging/recipes-connectivity/networkmanager/networkmanager_1.22.10.bbappend
+++ b/meta-ohos-staging/recipes-connectivity/networkmanager/networkmanager_1.22.10.bbappend
@@ -4,4 +4,6 @@
 
 FILESEXTRAPATHS_prepend := "${THISDIR}/${PN}-${PV}:"
 
-SRC_URI_append = " file://fix-reallocarray-check.patch"
+SRC_URI_append = " file://fix-reallocarray-check.patch \
+	file://fix-strerror_r.patch \
+"
-- 
GitLab