blob: 878914b30791d4fa7cf65bf330f50e38cf8225f1 [file] [log] [blame]
Andrew Geissler595f6302022-01-24 19:11:47 +00001From 873202f63f9f117c6e5a98e444cc709057042979 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
William A. Kennington IIIac69b482021-06-02 12:28:27 -07004Subject: [PATCH] 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>
William A. Kennington IIIac69b482021-06-02 12:28:27 -070021
Brad Bishop19323692019-04-05 15:28:33 -040022---
William A. Kennington IIIac69b482021-06-02 12:28:27 -070023 src/libsystemd/sd-bus/bus-error.c | 5 +++++
24 src/libsystemd/sd-journal/journal-send.c | 5 +++++
Brad Bishop19323692019-04-05 15:28:33 -040025 2 files changed, 10 insertions(+)
26
Andrew Geisslerd1e89492021-02-12 15:35:20 -060027--- a/src/libsystemd/sd-bus/bus-error.c
28+++ b/src/libsystemd/sd-bus/bus-error.c
Andrew Geissler7e0e3c02022-02-25 20:34:39 +000029@@ -409,7 +409,12 @@ static void bus_error_strerror(sd_bus_er
Brad Bishop19323692019-04-05 15:28:33 -040030 return;
31
32 errno = 0;
33+#ifndef __GLIBC__
34+ strerror_r(error, m, k);
35+ x = m;
36+#else
37 x = strerror_r(error, m, k);
38+#endif
39 if (errno == ERANGE || strlen(x) >= k - 1) {
40 free(m);
41 k *= 2;
William A. Kennington IIIac69b482021-06-02 12:28:27 -070042--- a/src/libsystemd/sd-journal/journal-send.c
43+++ b/src/libsystemd/sd-journal/journal-send.c
Andrew Geissler7e0e3c02022-02-25 20:34:39 +000044@@ -348,7 +348,12 @@ static int fill_iovec_perror_and_send(co
William A. Kennington IIIac69b482021-06-02 12:28:27 -070045 char* j;
46
47 errno = 0;
48+#ifndef __GLIBC__
49+ strerror_r(_saved_errno_, buffer + 8 + k, n - 8 - k);
50+ j = buffer + 8 + k;
51+#else
52 j = strerror_r(_saved_errno_, buffer + 8 + k, n - 8 - k);
53+#endif
54 if (errno == 0) {
55 char error[STRLEN("ERRNO=") + DECIMAL_STR_MAX(int) + 1];
56