Skip to content
Tcl Source Code View Ticket
Login

View Ticket

2012-07-08
18:36 • Closed ticket [3531209fff]: Improper support for IPv6 raw address in http librar... artifact: 2bba2306c6 user: rmax
12:13 • Ticket [3531209fff]: 1 change artifact: ba63711176 user: nijtmans
2012-07-06
15:20 • Ticket [3531209fff]: 4 changes artifact: fc977d9164 user: efrecon
2012-05-31
22:28 • New ticket [3531209fff]. artifact: d1d04642f0 user: efrecon

Improper support for IPv6 raw address in http library

Closed / Fixed3531209fffffffffffffffffffffffffffffffffCreated 15 years agoUpdated 14 years ago
Descriptionplain2012-05-31 22:28:35
The current implementation of the http library does not support URLs that contain raw IPv6 specifications, i.e. http://[2001:5c0:1400:b::d623]/ to take mine as an example. The problem is that the atom of the regexp that should match the host part of the authority is written as [^/:\#?]+ which will not work since IPv6 addresses are written using : as separators (well, not *entirely* true, but almost). Therefore, the parsing stops at improper places within the URL specification and ends up not being able to open the socket against the IP address, even though Tcl 8.6 now has support for IPv6.

The following code (extract out of the "parsing" part of the geturl procedure actually performs the work properly:

   set URLmatcher {(?x)                # this is _expanded_ syntax 
        ^ 
        (?: (\w+) : ) ?                        # <protocol scheme> 
        (?: // 
            ( [^/\#?]+ )                # <location=userinfo + host + port> 
        )? 
        ( / [^\#]*)?                        # <path> (including query) 
        (?: \# (.*) )?                        # <fragment> 
        $ 
    } 

    # Phase one: parse, the URL match 
    if {![regexp -- $URLmatcher $url -> proto location srvurl]} { 
        unset $token 
        return -code error "Unsupported URL: $url" 
    } 
    if { [string first "@" $location] >= 0 } { 
        foreach {user hostport} [split $location "@"] break 
    } else { 
        set user "" 
        set hostport $location 
    } 
    set idx [string last ":" $hostport] 
    if { $idx >= 0 } { 
        set port [string trimleft [string range $hostport $idx end] ":"] 
        if { [string is integer $port] } { 
            set host [string trimright [string range $hostport 0 $idx] ":"] 
        } else { 
            set port "" 
            set host $hostport 
        } 
    } else { 
        set port "" 
        set host $hostport 
    } 
    set host [string trim $host "\[\]"] 

    # Phase two: validate 

This version minimises the regexp parsing and adds a number of string operations. It's not perfect, but at least solve the issue. A regexp guru would be needed to fix this at the regexp level.
efreconplain2012-07-06 15:20:08
I have a copy of the fix above, as part of a copy of the http package, available for more readable code. See: http://code.google.com/p/efr-tools/source/browse/trunk/apps/cxManager/lib/http/http.tcl. I have used the code review facilities available at google code to further highlight the changes that I have made and what needs to be. Once again, this isn't a proper fix from my point of view, needs a regexp expert to fix the URL parsing instead.
nijtmans Ticket [3531209fff]: 1 change [History diff]2012-07-08 12:13:31
rmaxplain2012-07-08 18:36:48
allow_comments - 1

Fixed in Check-in [abc8fa71fe].
Log in (anonymous is fine) to add a comment.