comparison src/core/ngx_inet.c @ 2206:6ea36910aa57

fix bugs introduced in r2204
author Igor Sysoev <igor@sysoev.ru>
date Tue, 26 Aug 2008 16:11:30 +0000
parents 8e5bf1bc87e2
children 231b52f8adc0
comparison
equal deleted inserted replaced
2205:5398f47082f0 2206:6ea36910aa57
254 u_char *p, *host, *port, *last, *uri; 254 u_char *p, *host, *port, *last, *uri;
255 size_t len; 255 size_t len;
256 ngx_int_t n; 256 ngx_int_t n;
257 struct hostent *h; 257 struct hostent *h;
258 258
259 u->family = AF_INET;
260
259 host = u->url.data; 261 host = u->url.data;
260 262
261 last = host + u->url.len; 263 last = host + u->url.len;
262 264
263 port = ngx_strlchr(host, last, ':'); 265 port = ngx_strlchr(host, last, ':');
277 } 279 }
278 280
279 if (port) { 281 if (port) {
280 port++; 282 port++;
281 283
282 if (last - port == 0) { 284 len = last - port;
285
286 if (len == 0) {
283 u->err = "invalid port"; 287 u->err = "invalid port";
284 return NGX_ERROR; 288 return NGX_ERROR;
285 } 289 }
286 290
287 u->port_text.len = last - port; 291 n = ngx_atoi(port, len);
292
293 if (n < 1 || n > 65536) {
294 u->err = "invalid port";
295 return NGX_ERROR;
296 }
297
298 u->port = (in_port_t) n;
299
300 u->port_text.len = len;
288 u->port_text.data = port; 301 u->port_text.data = port;
289 302
290 last = port - 1; 303 last = port - 1;
291 304
292 } else { 305 } else {
329 len = 0; 342 len = 0;
330 } 343 }
331 344
332 u->host.len = len; 345 u->host.len = len;
333 u->host.data = host; 346 u->host.data = host;
347
348 if (u->no_resolve) {
349 return NGX_OK;
350 }
334 351
335 if (len++) { 352 if (len++) {
336 353
337 p = ngx_alloc(len, pool->log); 354 p = ngx_alloc(len, pool->log);
338 if (p == NULL) { 355 if (p == NULL) {
357 374
358 ngx_free(p); 375 ngx_free(p);
359 376
360 } else { 377 } else {
361 u->addr.in_addr = INADDR_ANY; 378 u->addr.in_addr = INADDR_ANY;
362 }
363
364 if (u->port_text.len) {
365
366 n = ngx_atoi(u->port_text.data, u->port_text.len);
367
368 if (n < 1 || n > 65536) {
369 u->err = "invalid port";
370 return NGX_ERROR;
371 }
372
373 u->port = (in_port_t) n;
374 }
375
376 u->family = AF_INET;
377
378 if (u->no_resolve) {
379 return NGX_OK;
380 } 379 }
381 380
382 if (u->no_port) { 381 if (u->no_port) {
383 u->port = u->default_port; 382 u->port = u->default_port;
384 } 383 }