0015-distinguish-XSI-compliant-strerror_r-from-GNU-specif.patch 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. From 0542d27ebbb250c09bdcfcf9f2ea3d27426fe522 Mon Sep 17 00:00:00 2001
  2. From: Chen Qi <Qi.Chen@windriver.com>
  3. Date: Tue, 10 Jul 2018 15:40:17 +0800
  4. Subject: [PATCH] distinguish XSI-compliant strerror_r from GNU-specifi
  5. strerror_r
  6. XSI-compliant strerror_r and GNU-specifi strerror_r are different.
  7. int strerror_r(int errnum, char *buf, size_t buflen);
  8. /* XSI-compliant */
  9. char *strerror_r(int errnum, char *buf, size_t buflen);
  10. /* GNU-specific */
  11. We need to distinguish between them. Otherwise, we'll get an int value
  12. assigned to (char *) variable, resulting in segment fault.
  13. Upstream-Status: Inappropriate [musl specific]
  14. Signed-off-by: Chen Qi <Qi.Chen@windriver.com>
  15. ---
  16. src/libsystemd/sd-bus/bus-error.c | 5 +++++
  17. src/libsystemd/sd-journal/journal-send.c | 5 +++++
  18. 2 files changed, 10 insertions(+)
  19. --- a/src/libsystemd/sd-bus/bus-error.c
  20. +++ b/src/libsystemd/sd-bus/bus-error.c
  21. @@ -409,7 +409,12 @@ static void bus_error_strerror(sd_bus_er
  22. return;
  23. errno = 0;
  24. +#ifndef __GLIBC__
  25. + strerror_r(error, m, k);
  26. + x = m;
  27. +#else
  28. x = strerror_r(error, m, k);
  29. +#endif
  30. if (errno == ERANGE || strlen(x) >= k - 1) {
  31. free(m);
  32. k *= 2;
  33. @@ -594,8 +599,12 @@ const char* _bus_error_message(const sd_
  34. if (e && e->message)
  35. return e->message;
  36. -
  37. +#ifndef __GLIBC__
  38. + strerror_r(abs(error), buf, ERRNO_BUF_LEN);
  39. + return buf;
  40. +#else
  41. return strerror_r(abs(error), buf, ERRNO_BUF_LEN);
  42. +#endif
  43. }
  44. static bool map_ok(const sd_bus_error_map *map) {
  45. --- a/src/libsystemd/sd-journal/journal-send.c
  46. +++ b/src/libsystemd/sd-journal/journal-send.c
  47. @@ -381,7 +381,12 @@ static int fill_iovec_perror_and_send(co
  48. char* j;
  49. errno = 0;
  50. +#ifndef __GLIBC__
  51. + strerror_r(_saved_errno_, buffer + 8 + k, n - 8 - k);
  52. + j = buffer + 8 + k;
  53. +#else
  54. j = strerror_r(_saved_errno_, buffer + 8 + k, n - 8 - k);
  55. +#endif
  56. if (errno == 0) {
  57. char error[STRLEN("ERRNO=") + DECIMAL_STR_MAX(int) + 1];