]> git.ipfire.org Git - thirdparty/squid.git/commit - src/cf.data.pre
Improve AnyP::Uri::port_ and related port storage types (#1255)
authorAlex Rousskov <rousskov@measurement-factory.com>
Mon, 27 Feb 2023 10:56:57 +0000 (10:56 +0000)
committerSquid Anubis <squid-anubis@squid-cache.org>
Mon, 27 Feb 2023 10:57:04 +0000 (10:57 +0000)
commit380b09ae86f86185ea5fa2f552d6aa34b68c4ed9
tree6e561076edea2d4f592c9b95113d08684f31a473
parent491933673f2492ffc7b2238ea0d5ac8308dd3160
Improve AnyP::Uri::port_ and related port storage types (#1255)

The old "unsigned short" type is used for various things all over the
code and cannot distinguish a parsed port zero from an absent port. In
theory, it could also hold values exceeding 65535, getting out of sync
with various (poorly duplicated) maximum port value checks.

No significant runtime changes are expected, but some transactions with
unknown request URI ports may now be reported correctly, showing "-"
instead of "0" for the missing port number. In some very special/rare
on_unsupported_protocol cases, Squid might no longer attempt to tunnel
non-HTTP requests to a zero port. Such attempts were failing anyway.

This change leaves many "unsigned short" port use cases untouched. Most
of them should be converted, but most (if not all) of those conversions
should be done in dedicated projects. Here are a few TODO highlights:

* ACLIntRange: Stores integers, is usable for integers, but assumes it
  is being configured with port numbers. We probably should enhance that
  class to handle "all" integers instead of expanding/deepening that
  rather limiting "input is just port numbers" assumption.

* CachePeer and internalRemoteUri(): Likely runtime changes related to
  squid.conf validity.

* Ftp::Server::listenForDataConnection() and friends: Triggers a few
  changes with runtime effects related to comm_local_port() failures.

* Ip::Address, Snmp::Session, fde: Too many low-level changes, some of
  which would be difficult to test.

* Config.Port.icp: Possible runtime changes related to squid.conf and
  command-line arguments validity.

Also used "%hu" instead of "%u" or "%d" to printf() ports. These changes
arguably improve code and might make some pedantic compiler happier, but
they do not fix any "real" bugs because variadic printf() arguments are
automatically promoted from short to int and, hence, printf()
implementations never get and never expect shorts.
19 files changed:
src/HttpRequest.cc
src/HttpRequest.h
src/acl/UrlPort.cc
src/anyp/Uri.cc
src/anyp/Uri.h
src/anyp/UriScheme.cc
src/anyp/UriScheme.h
src/carp.cc
src/cf.data.pre
src/client_side.cc
src/client_side.h
src/client_side_request.cc
src/clients/FtpGateway.cc
src/errorpage.cc
src/errorpage.h
src/format/Format.cc
src/peer_select.cc
src/tests/testHttpRequest.cc
src/wccp2.cc