blob: 5cdcf84dc1aec75299b53549a48799db16faed83 [file] [log] [blame]
Andrew Geisslerd1e89492021-02-12 15:35:20 -06001From e382845aed90cfe4496a8351d57d4466dd2e9a9c Mon Sep 17 00:00:00 2001
Brad Bishop19323692019-04-05 15:28:33 -04002From: Chen Qi <Qi.Chen@windriver.com>
3Date: Tue, 10 Jul 2018 15:40:17 +0800
Andrew Geisslerd1e89492021-02-12 15:35:20 -06004Subject: [PATCH 15/26] distinguish XSI-compliant strerror_r from GNU-specifi
Brad Bishop19323692019-04-05 15:28:33 -04005 strerror_r
6
7XSI-compliant strerror_r and GNU-specifi strerror_r are different.
8
9 int strerror_r(int errnum, char *buf, size_t buflen);
10 /* XSI-compliant */
11
12 char *strerror_r(int errnum, char *buf, size_t buflen);
13 /* GNU-specific */
14
15We need to distinguish between them. Otherwise, we'll get an int value
16assigned to (char *) variable, resulting in segment fault.
17
18Upstream-Status: Inappropriate [musl specific]
19
20Signed-off-by: Chen Qi <Qi.Chen@windriver.com>
21---
22 src/journal/journal-send.c | 5 +++++
23 src/libsystemd/sd-bus/bus-error.c | 5 +++++
24 2 files changed, 10 insertions(+)
25
Andrew Geisslerd1e89492021-02-12 15:35:20 -060026diff --git a/src/journal/journal-send.c b/src/journal/journal-send.c
27index e8e6ad555b..8ca5271d02 100644
28--- a/src/journal/journal-send.c
29+++ b/src/journal/journal-send.c
30@@ -348,7 +348,12 @@ static int fill_iovec_perror_and_send(const char *message, int skip, struct iove
Brad Bishop19323692019-04-05 15:28:33 -040031 char* j;
32
33 errno = 0;
34+#ifndef __GLIBC__
35+ strerror_r(_saved_errno_, buffer + 8 + k, n - 8 - k);
36+ j = buffer + 8 + k;
37+#else
38 j = strerror_r(_saved_errno_, buffer + 8 + k, n - 8 - k);
39+#endif
40 if (errno == 0) {
41 char error[STRLEN("ERRNO=") + DECIMAL_STR_MAX(int) + 1];
42
Andrew Geisslerd1e89492021-02-12 15:35:20 -060043diff --git a/src/libsystemd/sd-bus/bus-error.c b/src/libsystemd/sd-bus/bus-error.c
44index 8da2024a50..9605a9b869 100644
45--- a/src/libsystemd/sd-bus/bus-error.c
46+++ b/src/libsystemd/sd-bus/bus-error.c
47@@ -392,7 +392,12 @@ static void bus_error_strerror(sd_bus_error *e, int error) {
Brad Bishop19323692019-04-05 15:28:33 -040048 return;
49
50 errno = 0;
51+#ifndef __GLIBC__
52+ strerror_r(error, m, k);
53+ x = m;
54+#else
55 x = strerror_r(error, m, k);
56+#endif
57 if (errno == ERANGE || strlen(x) >= k - 1) {
58 free(m);
59 k *= 2;
Andrew Geisslerd1e89492021-02-12 15:35:20 -060060--
612.27.0
62