Index: trunk/extensions/CheckUser/checkuser.js |
— | — | @@ -27,33 +27,39 @@ |
28 | 28 | var bin_prefix = 0; |
29 | 29 | var prefix_cidr = 0; |
30 | 30 | var prefix = new String( "" ); |
31 | | - // Go through each IP in the list, get it's binary form, and track |
32 | | - // the largest binary prefix among them |
| 31 | + // Go through each IP in the list, get it's binary form, and |
| 32 | + // track the largest binary prefix among them... |
33 | 33 | for( var i=0; i<ips.length; i++ ) { |
| 34 | + var invalid = false; |
34 | 35 | // ...in the spirit of block.js, call this "addy" |
35 | 36 | var addy = ips[i]; |
36 | 37 | // Match the first IP in each list (ignore other garbage) |
37 | | - var ipV4 = addy.match(/(^|\b)(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})(\/\d+)?\b/); |
| 38 | + var ipV4 = addy.match(/(^|\b)(\d+\.\d+\.\d+\.\d+)(\/\d+)?\b/); |
38 | 39 | var ipV6 = addy.match(/(^|\b)(:(:[0-9A-Fa-f]{1,4}){1,7}|[0-9A-Fa-f]{1,4}(:{1,2}[0-9A-Fa-f]{1,4}|::$){1,7})(\/\d+)?\b/); |
39 | 40 | // Binary form |
40 | 41 | var bin = new String( "" ); |
41 | | - // Rebuilt formatted bin_prefix for each IP |
42 | | - if( ipV4 || ipV6 ) prefix = ''; |
43 | 42 | // Convert the IP to binary form: IPv4 |
44 | 43 | if( ipV4 ) { |
45 | 44 | var ip = ipV4[2]; |
46 | 45 | var cidr = ipV4[3]; // CIDR, if it exists |
47 | 46 | // Get each quad integer |
48 | 47 | var blocs = ip.split('.'); |
| 48 | + // IANA 1.0.0.0/8, 2.0.0.0/8 |
| 49 | + if( blocs[0] < 3 ) continue; |
49 | 50 | for( var x=0; x<blocs.length; x++ ) { |
50 | 51 | bloc = parseInt( blocs[x], 10 ); |
51 | | - if( bloc > 255 ) continue; // bad IP! |
| 52 | + if( bloc > 255 ) { |
| 53 | + invalid = true; // bad IP! |
| 54 | + break; // bad IP! |
| 55 | + } |
52 | 56 | bin_block = bloc.toString(2); // concat bin with binary form of bloc |
53 | 57 | while( bin_block.length < 8 ) { |
54 | 58 | bin_block = "0" + bin_block; // pad out as needed |
55 | 59 | } |
56 | 60 | bin += bin_block; |
57 | 61 | } |
| 62 | + if( invalid ) continue; // move to next IP |
| 63 | + prefix = ''; // Rebuild formatted bin_prefix for each IP |
58 | 64 | // Apply any valid CIDRs |
59 | 65 | if( cidr ) { |
60 | 66 | cidr = cidr.match( /\d+$/ )[0]; // get rid of slash |
— | — | @@ -119,7 +125,10 @@ |
120 | 126 | var blocs = ip.split(':'); |
121 | 127 | for( var x=0; x<=7; x++ ) { |
122 | 128 | bloc = blocs[x] ? blocs[x] : "0"; |
123 | | - if( bloc > "ffff" ) continue; // bad IP! |
| 129 | + if( bloc > "ffff" ) { |
| 130 | + invalid = true; // bad IP! |
| 131 | + break; // bad IP! |
| 132 | + } |
124 | 133 | int_block = hex2int( bloc ); // convert hex -> int |
125 | 134 | bin_block = int_block.toString(2); // concat bin with binary form of bloc |
126 | 135 | while( bin_block.length < 16 ) { |
— | — | @@ -127,6 +136,8 @@ |
128 | 137 | } |
129 | 138 | bin += bin_block; |
130 | 139 | } |
| 140 | + if( invalid ) continue; // move to next IP |
| 141 | + prefix = ''; // Rebuild formatted bin_prefix for each IP |
131 | 142 | // Apply any valid CIDRs |
132 | 143 | if( cidr ) { |
133 | 144 | cidr = cidr.match( /\d+$/ )[0]; // get rid of slash |