# Wether there is a bug to parse ipv6 url or not?

**URL:** <https://www.ruby-forum.com/t/wether-there-is-a-bug-to-parse-ipv6-url-or-not/203288>\
**Category:** NGINX\
**Created:** [February 17, 2011, 9:03am UTC](https://www.ruby-forum.com/t/wether-there-is-a-bug-to-parse-ipv6-url-or-not/203288 "2011-02-17T09:03:56Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![luislavena](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/0ea827/32.png) [@luislavena](https://www.ruby-forum.com/u/luislavena)\
**Post date:** [February 17, 2011, 9:03am UTC](https://www.ruby-forum.com/t/wether-there-is-a-bug-to-parse-ipv6-url-or-not/203288/1 "2011-02-17T09:03:56Z")

</div>

I’m reading the nginx0.9.1 source code.  
now I find a bug when I read the “ngx\_parse\_inet6\_url” function at 914  
line in ngx\_inet.c.  
the code don’t correctly get the length of port when parsing the url.  
for example:  
the ipv6 url is : “[::FFFF:129.144.52.38]:8080/index.html”

the code: plz see the red color part  
host = u-\>url.data + 1;  
last = u-\>url.data + u-\>url.len;

```
p = ngx_strlchr(host, last, ']');

if (p == NULL) {
    u->err = "invalid host";
    return NGX_ERROR;
}

if (last - p) {

    port = p + 1;

    uri = ngx_strlchr(port, last, '/');

    if (uri) {
        if (u->listen || !u->uri_part) {
            u->err = "invalid host";
            return NGX_ERROR;
        }

        u->uri.len = last - uri;
        u->uri.data = uri;
    }

    if (*port == ':') {
        port++;

        [color=#FF0033]len = last - port; //here......... last is

```

the end of url ,but not the position of 8080 [/color]  
…  
"

Posted at Nginx Forum:

> **[wether there is a bug to parse ipv6 url or not?](https://forum.nginx.org/read.php?2,176073,176073#msg-176073)**
>
> I'm reading the nginx0.9.1 source code. now I find a bug when I read the "ngx\_parse\_inet6\_url" function at 914 line in ngx\_inet.c. the code don't correctly get the length of port when parsing the url. for example: the ipv6 url is :...

---

<div class="post-metadata">

**Author:** ![garry.lgr](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/ea5d25/32.png) [@garry.lgr](https://www.ruby-forum.com/u/garry.lgr)\
**Post date:** [February 17, 2011, 4:12pm UTC](https://www.ruby-forum.com/t/wether-there-is-a-bug-to-parse-ipv6-url-or-not/203288/2 "2011-02-17T16:12:32Z")

</div>

Hello!

On Thu, Feb 17, 2011 at 03:01:57AM -0500, garry.lgr wrote:

> I’m reading the nginx0.9.1 source code.  
> now I find a bug when I read the “ngx\_parse\_inet6\_url” function at 914  
> line in ngx\_inet.c.  
> the code don’t correctly get the length of port when parsing the url.  
> for example:  
> the ipv6 url is : “[::FFFF:129.144.52.38]:8080/index.html”

[…]

> ```
> if (*port == ':') {
> port++;
> 
> [color=#FF0033]len = last - port; //here......... last is
> 
> ```
> 
> the end of url ,but not the position of 8080 [/color]  
> …  
> "

Yes, thank you, looks like a bug.

This shouldn’t affect any current usage of ngx\_parse\_inet6\_url()  
though, as IPv6 is only supported in listen directive, which  
shouldn’t contain uri part anyway (and ngx\_parse\_inet6\_url() will  
complain correctly about “invalid host” if uri part present for  
listen addresses).

Maxim D.
