1
0
mirror of https://github.com/bgp/bgpq4.git synced 2024-05-11 05:55:05 +00:00

networks with leading zeros (02.51.252.0/22) can't be parsed by inet_ntop().

This commit is contained in:
Alexandre Snarskii
2014-07-27 15:40:19 +04:00
parent 857c3dc15d
commit 50ebceaeff
2 changed files with 19 additions and 4 deletions

View File

@ -1,6 +1,8 @@
0.1.22 (not tagged yet)
0.1.22 (2014-07-27)
- bugfix: allow network object with stray spaces after prefix length.
Found by Tom Eichhorn in 2620:74:14::/48 (VeriSign Route6, RADB).
- bugfix: networks with leading zeros (02.51.252.0/22, as4787) are not
parsed correctly in inet_ntop.. Found by Tom Eichhorn.
0.1.21 (2014-06-05)
- new flag -b: generate prefix-filters for BIRD (http://bird.network.cz),

View File

@ -73,9 +73,22 @@ sx_prefix_parse(struct sx_prefix* p, int af, char* text)
};
if(inet_pton(af,text,&p->addr)!=1) {
if(c) *c='/';
sx_report(SX_ERROR,"Unable to parse prefix %s, af=%i\n",text,af);
goto fixups;
int aparts[4];
/* contrary to documentation (man inet_ntop on FreeBSD),
addresses with leading zeros are not parsed correctly. Try to
workaround this issue manually */
if (af==AF_INET && sscanf(text, "%i.%i.%i.%i", aparts,
aparts+1, aparts+2, aparts+3) == 4 && aparts[0]>=0 &&
aparts[0]<256 && aparts[1]>=0 && aparts[1]<256 &&
aparts[2]>=0 && aparts[2]<256 && aparts[3]>=0 &&
aparts[3]<256) {
p->addr.addr.s_addr = htonl((aparts[0]<<24) +
(aparts[1]<<16) + (aparts[2]<<8) + aparts[3]);
} else {
if(c) *c='/';
sx_report(SX_ERROR,"Unable to parse prefix %s, af=%i\n",text,af);
goto fixups;
};
};
if(af==AF_INET) {