On 14. 11. 2026 22:51, Rainer Jung wrote:
Am 14.11.26 um 11:46 schrieb Rainer Jung:
Am 14.11.26 um 07:43 schrieb Daniel Sahlberg:
fre 13 nov. 2026 kl. 14:44 skrev Rainer Jung <[email protected] <mailto:[email protected]>>:

    Am 13.11.26 um 14:00 schrieb Ruediger Pluem via dev:
     >>
     >> I can create a PR if this seems desirable.
     >
     > You can, but APR is still on Subversion :-)
    Oh well ...


I would say you can make a PR if that is what makes most sense to you. It is easy enough to extract the patch and apply to SVN and close the PR in one go.

I can do that if needed, although I’m not an expert in the code so I’d like a review from someone else.
Thanks Daniel. Sorry for the confusion. By PR I originally meant "suggest a patch". I have committed (minor) things to APR/APPU in the past, so I can do all necessary steps by myself.

I will change the code in APR trunk and add the patch to STATUS in APU 1.7 and 1.6.
Suggested patch:

Index: uri/apr_uri.c
===================================================================
--- uri/apr_uri.c    (Revision 1940324)
+++ uri/apr_uri.c    (Arbeitskopie)
@@ -900,6 +900,7 @@
     /* scheme must be non-empty and followed by : */
     if (s != uri && s[0] == ':') {
         uptr->scheme = apr_pstrmemdup(p, uri, s - uri);
+        uptr->port = apr_uri_port_of_scheme(uptr->scheme);
         s++;
     }
     else {
@@ -1017,7 +1018,6 @@
             /* Invalid characters after ':' found */
             return APR_EGENERAL;
         }
-        uptr->port = apr_uri_port_of_scheme(uptr->scheme);
         goto deal_with_path;
     }


It moves setting the port from the scheme directly to where the schemes is detected. The code further down deriving the port from a port explicitly contained in the URI does not check, whether port was already set and overwrites it. So instead of falling back to the default port, always set it from the scheme and then overwrite it, if one was explicitly given.


Your reasoning looks good.

The only thing that I find wrong (not in your patch per se, but in apr_uri_port_of_scheme()) is that it returns 0 if it doesn't know the scheme. That's a thinko: it should return an invalid port number or indicate the error in some other way. As it is, someone who passes in, say, "amqp://host/vhost" or any other unknown scheme will end up connecting to port 0 with no way to really guard against that.

Unfortunately, the way that function is declared, it can't just return −1 since cast to uint16, 65535 is a valid port number. Alternatively, apr_uri_parse() could interpret 0 as an error since no protocols are registered to port 0 – nor should there be. It could return an error status, a semantic change that's a bit late in the day. That might be fine on trunk, properly documented, but not on the 1.x branches.

At least there should be a documentation change noted in the release notes telling people to double check the port number in the parsed apr_uri_t before and/or the result of apr_port_of_scheme() before opening any connections with the results. Just as an example, the docstring for apr_port_of_scheme() lists a number of supported schemes that is far from complete, and it doesn't mention a returned 0 or what to do with it.


I'll wait a bit for comments before I apply it.

+1 to apply your patch. My murmuring above doesn't affect it. Please also mention it in CHANGES.

I am not sure what the current backport process to APU 1.7 and 1.6 is. Probably apply to 1.7 directly after APR trunk, but for 1.6 add it to STATUS?

Just apply the patch to the 1.7.x and 1.6.x. branches, along with the related CHANGES updates. It's all CTR.

-- Brane

Reply via email to