zhzh12312312 opened a new issue, #11577:
URL: https://github.com/apache/rocketmq/issues/11577

   ### Before Creating the Bug Report
   
   - [x] I found a bug, not just asking a question, which should be created in 
[GitHub Discussions](https://github.com/apache/rocketmq/discussions).
   
   - [x] I have searched the [GitHub 
Issues](https://github.com/apache/rocketmq/issues) and [GitHub 
Discussions](https://github.com/apache/rocketmq/discussions)  of this 
repository and believe that this is not a duplicate.
   
   - [x] I have confirmed that this bug belongs to the current repository, not 
other repositories of RocketMQ.
   
   
   ### Runtime platform environment
   
   All platforms. This is pure Java integer logic with no OS dependency. 
Reproduced on Linux (Alibaba Cloud Linux 8, x86_64).
   
   ### RocketMQ version
   
   branch: develop
   version: 5.5.1
   Git commit id: b1dadbd3d8a311dd79ce72a3899a64dbfa1bc455
   
   ### JDK Version
   
   Compiler: OpenJDK 11.0.33 (Eclipse Temurin), OS: Alibaba Cloud Linux 8 
(x86_64)
   Runtime (if different from JDK above): same as compiler
   
   ### Describe the Bug
   
   RemotingHelper.ipInCIDR(String ip, String cidr) computes the netmask as:
   
       int mask = 0xFFFFFFFF << (32 - netId);
   
   In Java an int shift count is taken modulo 32. For a /0 prefix, 32 - 0 == 32 
is reduced to 0, so the expression becomes 0xFFFFFFFF << 0 == -1. The resulting 
mask compares all 32 bits instead of none, so a catch-all CIDR such as 
0.0.0.0/0 only matches 0.0.0.0 itself and rejects every other address.
   
   This is also inconsistent with the newer implementation 
IPAddressUtils.isIPInRange(...), which correctly returns true for 
("192.168.1.1", "0.0.0.0/0").
   
   ### Steps to Reproduce
   
   RemotingHelper.ipInCIDR("192.168.1.1", "0.0.0.0/0") // returns false, 
expected true
   RemotingHelper.ipInCIDR("10.0.0.1",    "0.0.0.0/0") // returns false, 
expected true
   RemotingHelper.ipInCIDR("192.168.1.1", "192.168.1.0/24") // correct (true)
   
   ### What Did You Expect to See?
   
   A /0 prefix should match every IPv4 address, i.e. ipInCIDR(anyIp, 
"0.0.0.0/0") == true. This matches the meaning of the existing 
RemotingHelper.DEFAULT_CIDR_ALL = "0.0.0.0/0" constant.
   
   ### What Did You See Instead?
   
   ipInCIDR returns false for every address except 0.0.0.0 when the prefix is 
/0.
   
   ### Additional Context
   
   NettyRemotingClient#getProxy currently works around this by checking 
RemotingHelper.DEFAULT_CIDR_ALL.equals(cidr) before calling ipInCIDR. That 
workaround also covers a different concern (non-IPv4 hosts) so it is kept, but 
the public utility is still incorrect for any other caller. I will submit a PR 
that fixes the mask computation and adds a regression test.


-- 
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]

Reply via email to