summaryrefslogtreecommitdiffstats
path: root/rpc
diff options
context:
space:
mode:
authorAmar Tumballi <amar@kadalu.io>2019-11-26 12:53:11 +0530
committerAmar Tumballi <amarts@gmail.com>2019-11-27 07:16:24 +0000
commitd60935d1011e387115e0445629976196f566b3b1 (patch)
treec1b0095cae48aa5626c7c44fbbf9adc453a9d546 /rpc
parent337e6d6b7c6612a4ce360c9e4d1a484436cdef57 (diff)
pcsvc: 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: #765 Change-Id: I5d31468eb917aa94cbb85f573b37c60023e9daf3 Signed-off-by: Amar Tumballi <amar@kadalu.io>
Diffstat (limited to 'rpc')
-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 2818f62..623523c 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);