Browse code

- str2ip & str2ip6 used to accept ip addresses with to few dots/colons (e.g. 127.0 => 127.0.0.0 or ff02:1 => ff02:1::), now they are more strict

Andrei Pelinescu-Onciul authored on 25/02/2004 18:48:57
Showing 1 changed files
... ...
@@ -156,12 +156,14 @@ static inline struct ip_addr* str2ip(str* st)
156 156
 				goto error_char;
157 157
 		}
158 158
 	}
159
+	if (i<3) goto error_dots;
159 160
 	ip.af=AF_INET;
160 161
 	ip.len=4;
161 162
 	
162 163
 	return &ip;
163 164
 error_dots:
164
-	DBG("str2ip: ERROR: too many dots in [%.*s]\n", st->len, st->s);
165
+	DBG("str2ip: ERROR: too %s dots in [%.*s]\n", (i>3)?"many":"few", 
166
+			st->len, st->s);
165 167
 	return 0;
166 168
  error_char:
167 169
 	/*
... ...
@@ -228,7 +230,6 @@ static inline struct ip_addr* str2ip6(str* st)
228 230
 			goto error_char;
229 231
 		}
230 232
 	}
231
-	if (no_colons<2) goto error_too_few_colons;
232 233
 	if (!double_colon){ /* not ending in ':' */
233 234
 		addr[i]=htons(addr[i]);
234 235
 		i++; 
... ...
@@ -237,6 +238,9 @@ static inline struct ip_addr* str2ip6(str* st)
237 238
 	if (addr==addr_end){
238 239
 		rest=8-i-idx1;
239 240
 		memcpy(addr_start+idx1+rest, addr_end, i*sizeof(unsigned short));
241
+	}else{
242
+		/* no double colons inside */
243
+		if (no_colons<7) goto error_too_few_colons;
240 244
 	}
241 245
 /*
242 246
 	DBG("str2ip6: idx1=%d, rest=%d, no_colons=%d, hex=%x\n",