1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
|
From 790b56fcbce73e3335565eb1d8f0cdab5e596dba Mon Sep 17 00:00:00 2001
From: Natanael Copa <ncopa@alpinelinux.org>
Date: Mon, 24 Aug 2015 11:55:59 +0200
Subject: [PATCH] Fix segfault with musl libc due to bad use of strerror_r
The only known implementation that has the GNU variand of strerror_r is
GNU libc. Building with musl libc and _GNU_SOURCE enables some other gnu
extensions, but musl libc does not implement the broken strerror_r.
We fix thsi by check explicitly for GNU libc in addition to _GNU_SOURCE
and if they both are not set, then fall back to standard.
This fixes segfault with musl libc.
---
strings/my_vsnprintf.c | 6 +-----
1 file changed, 1 insertion(+), 5 deletions(-)
diff --git a/strings/my_vsnprintf.c b/strings/my_vsnprintf.c
index 1584a9e..4a10413 100644
--- a/strings/my_vsnprintf.c
+++ b/strings/my_vsnprintf.c
@@ -827,11 +827,7 @@ void my_strerror(char *buf, size_t len, int nr)
*/
#if defined(__WIN__)
strerror_s(buf, len, nr);
-#elif ((defined _POSIX_C_SOURCE && (_POSIX_C_SOURCE >= 200112L)) || \
- (defined _XOPEN_SOURCE && (_XOPEN_SOURCE >= 600))) && \
- ! defined _GNU_SOURCE
- strerror_r(nr, buf, len); /* I can build with or without GNU */
-#elif defined _GNU_SOURCE
+#elif defined(__GLIBC__) && defined(_GNU_SOURCE)
char *r= strerror_r(nr, buf, len);
if (r != buf) /* Want to help, GNU? */
strmake(buf, r, len - 1); /* Then don't. */
--
2.5.0
|