zjncs opened a new pull request, #11068:
URL: https://github.com/apache/rocketmq/pull/11068
### Motivation
`RemotingHelper.ipInCIDR` computes the netmask as:
```java
int mask = 0xFFFFFFFF << (32 - netId);
```
For `netId == 0` the shift distance is 32, which Java takes mod 32 — the
shift is a no-op and `mask` stays `0xFFFFFFFF` instead of `0`. So a `/0` CIDR
matches nothing except its own address:
```java
ipInCIDR("1.2.3.4", "0.0.0.0/0") // returns false, should be true
```
Reachability: `NettyRemotingClient.getProxy` guards only the exact string
`"0.0.0.0/0"` (`DEFAULT_CIDR_ALL.equals(cidr)`) before calling `ipInCIDR`, so a
socks proxy configured with any other `/0` CIDR (e.g. `10.0.0.0/0`) silently
never matches and the traffic bypasses the configured proxy. `/1`–`/32` are
unaffected.
### Modifications
Use a zero mask when the prefix length is 0.
### Verification
Fail-before (new test class `RemotingHelperTest`, run against the unpatched
code):
```
Tests run: 2, Failures: 1 --
RemotingHelperTest#testIpInCidrMatchesEverythingForZeroPrefixLength
```
Pass-after:
```
Tests run: 2, Failures: 0, Errors: 0, Skipped: 0 -- RemotingHelperTest
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]