You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

89 lines
2.5 KiB

  1. From 82014a5fa9930b0875e57869265acf011772277c Mon Sep 17 00:00:00 2001
  2. From: Stijn Tintel <stijn@linux-ipv6.be>
  3. Date: Sun, 3 May 2020 20:56:58 +0300
  4. Subject: [PATCH] network: avoid segfault in freeaddrinfo
  5. Calling freeaddrinfo(NULL) when using musl libc causes a segfault.
  6. Signed-off-by: Stijn Tintel <stijn@linux-ipv6.be>
  7. ---
  8. anet.c | 15 ++++++++++++---
  9. net_io.c | 5 ++++-
  10. viewadsb.c | 5 ++++-
  11. 3 files changed, 20 insertions(+), 5 deletions(-)
  12. diff --git a/anet.c b/anet.c
  13. index 5c35ff8..7f01958 100644
  14. --- a/anet.c
  15. +++ b/anet.c
  16. @@ -212,7 +212,10 @@ static int anetTcpGenericConnect(char *err, char *addr, char *service, int flags
  17. if (ss) {
  18. memcpy(ss, p->ai_addr, sizeof(*ss));
  19. }
  20. - freeaddrinfo(gai_result);
  21. + if (gai_result) {
  22. + freeaddrinfo(gai_result);
  23. + gai_result = NULL;
  24. + }
  25. return s;
  26. }
  27. @@ -220,7 +223,10 @@ static int anetTcpGenericConnect(char *err, char *addr, char *service, int flags
  28. anetCloseSocket(s);
  29. }
  30. - freeaddrinfo(gai_result);
  31. + if (gai_result) {
  32. + freeaddrinfo(gai_result);
  33. + gai_result = NULL;
  34. + }
  35. return ANET_ERR;
  36. }
  37. @@ -368,7 +374,10 @@ int anetTcpServer(char *err, char *service, char *bindaddr, int *fds, int nfds)
  38. fds[i++] = s;
  39. }
  40. - freeaddrinfo(gai_result);
  41. + if (gai_result) {
  42. + freeaddrinfo(gai_result);
  43. + gai_result = NULL;
  44. + }
  45. return (i > 0 ? i : ANET_ERR);
  46. }
  47. diff --git a/net_io.c b/net_io.c
  48. index 1f4d848..5f59194 100644
  49. --- a/net_io.c
  50. +++ b/net_io.c
  51. @@ -3285,7 +3285,10 @@ void cleanupNetwork(void) {
  52. for (int i = 0; i < Modes.net_connectors_count; i++) {
  53. struct net_connector *con = Modes.net_connectors[i];
  54. free(con->address);
  55. - freeaddrinfo(con->addr_info);
  56. + if (con->addr_info) {
  57. + freeaddrinfo(con->addr_info);
  58. + con->addr_info = NULL;
  59. + }
  60. if (con->mutex) {
  61. pthread_mutex_unlock(con->mutex);
  62. pthread_mutex_destroy(con->mutex);
  63. diff --git a/viewadsb.c b/viewadsb.c
  64. index 5fc5386..ad7b1bd 100644
  65. --- a/viewadsb.c
  66. +++ b/viewadsb.c
  67. @@ -308,7 +308,10 @@ int main(int argc, char **argv) {
  68. }
  69. // Free local service and client
  70. if (s) free(s);
  71. - freeaddrinfo(con->addr_info);
  72. + if (con->addr_info) {
  73. + freeaddrinfo(con->addr_info);
  74. + con->addr_info = NULL;
  75. + }
  76. pthread_mutex_unlock(con->mutex);
  77. pthread_mutex_destroy(con->mutex);
  78. free(con->mutex);
  79. --
  80. 2.26.2