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