summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAmar Tumballi <amar@kadalu.io>2019-11-26 12:53:11 +0530
committerAmar Tumballi <amarts@gmail.com>2019-11-28 10:03:04 +0000
commit2a5480c013982c1edb04d96dd04c989325b02388 (patch)
tree8f0a0a2d64136f5c3afe4e22232f03c6a25c9c1c
parentada2e64bbf4dbf555c5a5c19989eafed1893a137 (diff)
rpcsvc: fix subnet_mask_v4 check
The check we had for subnet mask validation wasn't checking in proper sequence. Corrected the order of calling `inet_pton()` as the fix. Fixes: bz#1777769 Change-Id: I5d31468eb917aa94cbb85f573b37c60023e9daf3 Signed-off-by: Amar Tumballi <amar@kadalu.io> (cherry picked from commit d60935d1011e387115e0445629976196f566b3b1)
-rw-r--r--rpc/rpc-lib/src/rpcsvc.c11
1 files changed, 7 insertions, 4 deletions
diff --git a/rpc/rpc-lib/src/rpcsvc.c b/rpc/rpc-lib/src/rpcsvc.c
index 5639abbb204..0daa54d536d 100644
--- a/rpc/rpc-lib/src/rpcsvc.c
+++ b/rpc/rpc-lib/src/rpcsvc.c
@@ -3196,10 +3196,6 @@ rpcsvc_match_subnet_v4(const char *addrtok, const char *ipaddr)
if (inet_pton(AF_INET, ipaddr, &sin1.sin_addr) == 0)
goto out;
- /* Find the network socket addr of subnet pattern */
- if (inet_pton(AF_INET, netaddr, &sin2.sin_addr) == 0)
- goto out;
-
slash = strchr(netaddr, '/');
if (slash) {
*slash = '\0';
@@ -3212,9 +3208,16 @@ rpcsvc_match_subnet_v4(const char *addrtok, const char *ipaddr)
if (prefixlen > 31)
goto out;
} else {
+ /* if there is no '/', then this function wouldn't be called */
goto out;
}
+ /* Need to do this after removing '/', as inet_pton() take IP address as
+ * second argument. Once we get sin2, then comparison is oranges to orange
+ */
+ if (inet_pton(AF_INET, netaddr, &sin2.sin_addr) == 0)
+ goto out;
+
shift = IPv4_ADDR_SIZE - prefixlen;
mask.sin_addr.s_addr = htonl((uint32_t)~0 << shift);