You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@trafficserver.apache.org by Cynthia Gu <cz...@linkedin.com.INVALID> on 2014/11/11 02:35:11 UTC

TS-1570

Hi,

I’m investigating this bug (https://issues.apache.org/jira/browse/TS-1570 ) and found that the root cause is in HTTPHdr::_fill_target_cache(). It processes port string and stops before the non-digit char. Pasting the code below:

// Check in the URL first, then the HOST field.
if (0 != url->host_get(&m_host_length))

{ m_target_in_url = true; m_port = url->port_get(); m_port_in_header = 0 != url->port_get_raw(); m_host_mime = NULL; }

else if (0 != (m_host_mime = const_cast<HTTPHdr*>(this)->get_host_port_values(0, &m_host_length, &port_ptr, 0))) {
if (port_ptr)

{ m_port = 0; for ( ; is_digit(*port_ptr) ; ++port_ptr ) m_port = m_port * 10 + *port_ptr - '0'; m_port_in_header = (0 != m_port); }

m_port = url_canonicalize_port(url->m_url_impl->m_url_type, m_port);
}

I think a better practice is to let validation check happen as soon as possible in the system and this function is not a good place for validations for the following reasons:

  1.  This always returns a valid/canonical port number to the caller. Callers in the existing code may depend on this feature.
  2.  Validation should happen as early as possible to save the resource in ATS
  3.  There should be a thorough validation including the possibility of integer overflow when converting the port number from a string

My current question is that if anybody knows that if there exists such functionality in ATS that I can reuse. If not, where is the best place to add it.

Thanks,
Cynthia



Re: TS-1570

Posted by "Alan M. Carroll" <am...@network-geographics.com>.
Yes. I looked at the code a bit last night and it would possible, but difficult, to return a parse fail value from that logic because of how is used.

As Cynthia noted, the fundamental problem is the HOST field is not checked for validity during the initial request parsing and after that, the request is presumed to be sufficiently correct. My first impression would be to put a special check for the HOST field in http_parser_parse_req() which is the top level function for parsing and validating the incoming request. You would need to check the return value from mime_parser_parse and if DONE then check the HOST field if present. We may want to check for presence as well, since it is a required field for HTTP 1.1.

As for code to do the HOST field checking, I don't know of any. For the port, I'd be tempted to re-use the logic from _fill_target_cache with a check per loop of going over 65536 (you're not going to overflow from a valid port valid on a single digit).