summaryrefslogtreecommitdiffstats
path: root/meta/recipes-core/systemd/systemd/0015-distinguish-XSI-compliant-strerror_r-from-GNU-specif.patch
blob: 7533fde1e1217236b595b72133b5624e746abf1a (plain)
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
From 0542d27ebbb250c09bdcfcf9f2ea3d27426fe522 Mon Sep 17 00:00:00 2001
From: Chen Qi <Qi.Chen@windriver.com>
Date: Tue, 10 Jul 2018 15:40:17 +0800
Subject: [PATCH] distinguish XSI-compliant strerror_r from GNU-specifi
 strerror_r

XSI-compliant strerror_r and GNU-specifi strerror_r are different.

       int strerror_r(int errnum, char *buf, size_t buflen);
                   /* XSI-compliant */

       char *strerror_r(int errnum, char *buf, size_t buflen);
                   /* GNU-specific */

We need to distinguish between them. Otherwise, we'll get an int value
assigned to (char *) variable, resulting in segment fault.

Upstream-Status: Inappropriate [musl specific]

Signed-off-by: Chen Qi <Qi.Chen@windriver.com>

---
 src/libsystemd/sd-bus/bus-error.c        | 5 +++++
 src/libsystemd/sd-journal/journal-send.c | 5 +++++
 2 files changed, 10 insertions(+)

--- a/src/libsystemd/sd-bus/bus-error.c
+++ b/src/libsystemd/sd-bus/bus-error.c
@@ -409,7 +409,12 @@ static void bus_error_strerror(sd_bus_er
                         return;
 
                 errno = 0;
+#ifndef __GLIBC__
+                strerror_r(error, m, k);
+                x = m;
+#else
                 x = strerror_r(error, m, k);
+#endif
                 if (errno == ERANGE || strlen(x) >= k - 1) {
                         free(m);
                         k *= 2;
@@ -594,8 +599,12 @@ const char* _bus_error_message(const sd_
 
         if (e && e->message)
                 return e->message;
-
+#ifndef __GLIBC__
+        strerror_r(abs(error), buf, ERRNO_BUF_LEN);
+        return buf;
+#else
         return strerror_r(abs(error), buf, ERRNO_BUF_LEN);
+#endif
 }
 
 static bool map_ok(const sd_bus_error_map *map) {
--- a/src/libsystemd/sd-journal/journal-send.c
+++ b/src/libsystemd/sd-journal/journal-send.c
@@ -381,7 +381,12 @@ static int fill_iovec_perror_and_send(co
                 char* j;
 
                 errno = 0;
+#ifndef __GLIBC__
+                strerror_r(_saved_errno_, buffer + 8 + k, n - 8 - k);
+                j = buffer + 8 + k;
+#else
                 j = strerror_r(_saved_errno_, buffer + 8 + k, n - 8 - k);
+#endif
                 if (errno == 0) {
                         char error[STRLEN("ERRNO=") + DECIMAL_STR_MAX(int) + 1];