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.

80 lines
2.2 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. --- a/anet.c
  13. +++ b/anet.c
  14. @@ -212,7 +212,10 @@ static int anetTcpGenericConnect(char *e
  15. if (ss) {
  16. memcpy(ss, p->ai_addr, sizeof(*ss));
  17. }
  18. - freeaddrinfo(gai_result);
  19. + if (gai_result) {
  20. + freeaddrinfo(gai_result);
  21. + gai_result = NULL;
  22. + }
  23. return s;
  24. }
  25. @@ -220,7 +223,10 @@ static int anetTcpGenericConnect(char *e
  26. anetCloseSocket(s);
  27. }
  28. - freeaddrinfo(gai_result);
  29. + if (gai_result) {
  30. + freeaddrinfo(gai_result);
  31. + gai_result = NULL;
  32. + }
  33. return ANET_ERR;
  34. }
  35. @@ -368,7 +374,10 @@ int anetTcpServer(char *err, char *servi
  36. fds[i++] = s;
  37. }
  38. - freeaddrinfo(gai_result);
  39. + if (gai_result) {
  40. + freeaddrinfo(gai_result);
  41. + gai_result = NULL;
  42. + }
  43. return (i > 0 ? i : ANET_ERR);
  44. }
  45. --- a/net_io.c
  46. +++ b/net_io.c
  47. @@ -3285,7 +3285,10 @@ void cleanupNetwork(void) {
  48. for (int i = 0; i < Modes.net_connectors_count; i++) {
  49. struct net_connector *con = Modes.net_connectors[i];
  50. free(con->address);
  51. - freeaddrinfo(con->addr_info);
  52. + if (con->addr_info) {
  53. + freeaddrinfo(con->addr_info);
  54. + con->addr_info = NULL;
  55. + }
  56. if (con->mutex) {
  57. pthread_mutex_unlock(con->mutex);
  58. pthread_mutex_destroy(con->mutex);
  59. --- a/viewadsb.c
  60. +++ b/viewadsb.c
  61. @@ -308,7 +308,10 @@ int main(int argc, char **argv) {
  62. }
  63. // Free local service and client
  64. if (s) free(s);
  65. - freeaddrinfo(con->addr_info);
  66. + if (con->addr_info) {
  67. + freeaddrinfo(con->addr_info);
  68. + con->addr_info = NULL;
  69. + }
  70. pthread_mutex_unlock(con->mutex);
  71. pthread_mutex_destroy(con->mutex);
  72. free(con->mutex);