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


Reply via email to