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.

90 lines
2.7 KiB

  1. From bfa850db67e150e8d44093a14ef6a9999c5c9968 Mon Sep 17 00:00:00 2001
  2. From: Oliver Kurth <okurth@vmware.com>
  3. Date: Wed, 29 Aug 2018 13:29:43 -0700
  4. Subject: [PATCH] Fix some bad derefs in primary NIC gathering code.
  5. Found by user in https://github.com/vmware/open-vm-tools/issues/272
  6. Debug code tries to access a struct field that may not have been initialized.
  7. - Pointer deref'd without a sanity check.
  8. ---
  9. open-vm-tools/lib/nicInfo/nicInfoPosix.c | 39 +++++++++++++++++++++-----------
  10. 1 file changed, 26 insertions(+), 13 deletions(-)
  11. diff --git a/lib/nicInfo/nicInfoPosix.c b/lib/nicInfo/nicInfoPosix.c
  12. index 8a063a0..31c1d1a 100644
  13. --- a/lib/nicInfo/nicInfoPosix.c
  14. +++ b/lib/nicInfo/nicInfoPosix.c
  15. @@ -359,7 +359,7 @@ GuestInfoGetNicInfo(unsigned int maxIPv4Routes,
  16. /* Get a handle to read the network interface configuration details. */
  17. if ((intf = intf_open()) == NULL) {
  18. - g_debug("Error, failed NULL result from intf_open()\n");
  19. + g_warning("%s: intf_open() failed\n", __FUNCTION__);
  20. return FALSE;
  21. }
  22. @@ -466,7 +466,15 @@ GuestInfoGetPrimaryIP(void)
  23. * the first non-loopback, internet interface in the interface list.
  24. */
  25. for (curr = ifaces; curr != NULL; curr = curr->ifa_next) {
  26. - int currFamily = ((struct sockaddr_storage *)curr->ifa_addr)->ss_family;
  27. + int currFamily;
  28. +
  29. + /*
  30. + * Some interfaces ("tun") have no ifa_addr, so ignore them.
  31. + */
  32. + if (NULL == curr->ifa_addr) {
  33. + continue;
  34. + }
  35. + currFamily = ((struct sockaddr_storage *)curr->ifa_addr)->ss_family;
  36. if (!(curr->ifa_flags & IFF_UP) || curr->ifa_flags & IFF_LOOPBACK) {
  37. continue;
  38. @@ -500,6 +508,7 @@ GuestInfoGetPrimaryIP(void)
  39. }
  40. #else
  41. +
  42. #ifndef NO_DNET
  43. char *
  44. @@ -508,20 +517,24 @@ GuestInfoGetPrimaryIP(void)
  45. GuestInfoIpPriority ipp;
  46. intf_t *intf = intf_open();
  47. - if (intf != NULL) {
  48. - ipp.ipstr = NULL;
  49. - for (ipp.priority = NICINFO_PRIORITY_PRIMARY;
  50. - ipp.priority < NICINFO_PRIORITY_MAX;
  51. - ipp.priority++){
  52. - intf_loop(intf, GuestInfoGetIntf, &ipp);
  53. - if (ipp.ipstr != NULL) {
  54. - break;
  55. - }
  56. + if (NULL == intf) {
  57. + g_warning("%s: intf_open() failed\n", __FUNCTION__);
  58. + return NULL;
  59. + }
  60. +
  61. + ipp.ipstr = NULL;
  62. + for (ipp.priority = NICINFO_PRIORITY_PRIMARY;
  63. + ipp.priority < NICINFO_PRIORITY_MAX;
  64. + ipp.priority++){
  65. + intf_loop(intf, GuestInfoGetIntf, &ipp);
  66. + if (ipp.ipstr != NULL) {
  67. + break;
  68. }
  69. - intf_close(intf);
  70. }
  71. + intf_close(intf);
  72. - g_debug("%s: returning '%s'", __FUNCTION__, ipp.ipstr);
  73. + g_debug("%s: returning '%s'",
  74. + __FUNCTION__, ipp.ipstr ? ipp.ipstr : "<null>");
  75. return ipp.ipstr;
  76. }
  77. --
  78. 2.7.4