get_proximity() crashes on interfaces with no addresses
Since commit aa6f7793 [autofs-5.0.7 - fix ipv6 proximity calculation] uses getifaddrs however it crashes on interfaces with no addresses. Fix the NULL check to ignore interfaces with no addresses.
Should it also check for the IFF_UP flag?
Doug
modules/replicated.c +2 -2
@@ -166,7 +166,7 @@ this = ifa;while (this) {if (this->ifa_flags &IFF_POINTOPOINT || - this->ifa_addr->sa_data ==NULL ) { + this->ifa_addr ==NULL ) { this = this->ifa_next;continue ; }
@@ -203,7 +203,7 @@ this = ifa;while (this) {if (this->ifa_flags &IFF_POINTOPOINT || - this->ifa_addr->sa_data ==NULL ) { + this->ifa_addr ==NULL ) { this = this->ifa_next;continue ; }
Quoted 3 lines · Doug Nazar
Since commit
aa6f7793[autofs-5.0.7 - fix ipv6 proximity calculation] uses getifaddrs however it crashes on interfaces with no addresses. Fix the NULL check to ignore interfaces with no addresses.
Hi,
Your patch removes the check on ifa_addr->sa_data. I'm wondering if it's possible to have a valid ifa_addr and a NULL sa_data. Do you know? Maybe it's safer to just test both:
if (this->ifa_flags & IFF_POINTOPOINT ||
this->ifa_addr == NULL ||
this->ifa_addr->sa_data == NULL) { this = this->ifa_next;
continue;
}
Quoted 1 line
Should it also check for the
IFF_UPflag?
I think it makes sense to test it.
Thanks,
Leonardo
Quoted 7 lines · Leonardo Chiquitto
Quoted 3 lines · Doug Nazar
Since commit
aa6f7793[autofs-5.0.7 - fix ipv6 proximity calculation] uses getifaddrs however it crashes on interfaces with no addresses. Fix the NULL check to ignore interfaces with no addresses.Your patch removes the check on
ifa_addr->sa_data. I'm wondering if it's possible to have a validifa_addrand a NULLsa_data. Do you know? Maybe it's safer to just test both:
I don't see how. ifa_addr is of type struct sockaddr. The sa_data field is a char array and only has meaning after interpreting the sa_family field.
Quoted 3 lines
Quoted 1 line
Should it also check for the
IFF_UPflag?I think it makes sense to test it.
Ok, here you go.
Doug
commit d0b5d4961004a41f6881b2ac2bb32ba3002654e5
Author: Doug Nazar <[email protected]> Date: Sun May 12 16:22:04 2013 -0400
Since commit aa6f7793 [autofs-5.0.7 - fix ipv6 proximity calculation] get_proximity() uses getifaddrs however it crashes on interfaces with no addresses. Fix the NULL check to ignore interfaces with no addresses.
Also skip interfaces which are not currently running.
modules/replicated.c +6 -4
@@ -165,8 +165,9 @@ static unsigned int get_proximity(struct sockaddr *host_addr) this = ifa;while (this) { -if (this->ifa_flags &IFF_POINTOPOINT || - this->ifa_addr->sa_data ==NULL ) { +if (!(this->ifa_flags &IFF_UP ) || + this->ifa_flags &IFF_POINTOPOINT || + this->ifa_addr ==NULL ) { this = this->ifa_next;continue ; }
@@ -202,8 +203,9 @@ static unsigned int get_proximity(struct sockaddr *host_addr) this = ifa;while (this) { -if (this->ifa_flags &IFF_POINTOPOINT || - this->ifa_addr->sa_data ==NULL ) { +if (!(this->ifa_flags &IFF_UP ) || + this->ifa_flags &IFF_POINTOPOINT || + this->ifa_addr ==NULL ) { this = this->ifa_next;continue ; }
Ian Kent
maintainerQuoted 11 lines · Doug Nazar
Quoted 7 lines · Leonardo Chiquitto
Quoted 3 lines · Doug Nazar
Since commit
aa6f7793[autofs-5.0.7 - fix ipv6 proximity calculation] uses getifaddrs however it crashes on interfaces with no addresses. Fix the NULL check to ignore interfaces with no addresses.Your patch removes the check on
ifa_addr->sa_data. I'm wondering if it's possible to have a validifa_addrand a NULLsa_data. Do you know? Maybe it's safer to just test both:I don't see how.
ifa_addris of type struct sockaddr. Thesa_datafield is a char array and only has meaning after interpreting thesa_familyfield.
You would think so, I'll go with this.
Quoted 3 lines
Quoted 3 lines
Quoted 2 lines
Should it also check for the
IFF_UPflag?I think it makes sense to test it.
Indeed that's probably good to do too.
I'd be interested to hear if this patch functions OK with the IFF_UP check in place.
In the mean time I'll add the patch to my queue for the next commit.
Ian
Quoted 1 line · Ian Kent
Indeed that's probably good to do too. I'd be interested to hear if this patch functions OK with the
IFF_UPcheck in place. In the mean time I'll add the patch to my queue for the next commit.
I've been running it for a day on a few boxes with no problems. The only additional line is a logging line I had when originally testing.
May 14 04:58:47 cockatrice automount[365]: get_proximity:168: getifaddrs: ifa_name lo, ifa_flags 0x00010049 May 14 04:58:47 cockatrice automount[365]: get_proximity:168: getifaddrs: ifa_name eql, ifa_flags 0x00000400 May 14 04:58:47 cockatrice automount[365]: get_proximity:168: getifaddrs: ifa_name eth0, ifa_flags 0x00011043 May 14 04:58:47 cockatrice automount[365]: get_proximity:168: getifaddrs: ifa_name wlan0, ifa_flags 0x00001002 May 14 04:58:47 cockatrice automount[365]: get_proximity:168: getifaddrs: ifa_name wmon0, ifa_flags 0x00011043
IFF_UP is 0x01 so that looks correct. eql was the one that it was crashing on with no ifa_addr.
Doug
Ian Kent
maintainerQuoted 17 lines · Doug Nazar
Quoted 3 lines · Ian Kent
Indeed that's probably good to do too. I'd be interested to hear if this patch functions OK with the
IFF_UPcheck in place. In the mean time I'll add the patch to my queue for the next commit.I've been running it for a day on a few boxes with no problems. The only additional line is a logging line I had when originally testing.
May 14 04:58:47 cockatrice automount[365]: get_proximity:168: getifaddrs: ifa_name lo, ifa_flags 0x00010049 May 14 04:58:47 cockatrice automount[365]: get_proximity:168: getifaddrs: ifa_name eql, ifa_flags 0x00000400 May 14 04:58:47 cockatrice automount[365]: get_proximity:168: getifaddrs: ifa_name eth0, ifa_flags 0x00011043 May 14 04:58:47 cockatrice automount[365]: get_proximity:168: getifaddrs: ifa_name wlan0, ifa_flags 0x00001002 May 14 04:58:47 cockatrice automount[365]: get_proximity:168:
Quoted 4 lines
getifaddrs:
ifa_namewmon0,ifa_flags0x00011043
IFF_UPis0x01so that looks correct. eql was the one that it was crashing on with noifa_addr.
OK, thanks for this.
Quoted 3 lines
Doug