From d60935d1011e387115e0445629976196f566b3b1 Mon Sep 17 00:00:00 2001 From: Amar Tumballi Date: Tue, 26 Nov 2019 12:53:11 +0530 Subject: 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 --- rpc/rpc-lib/src/rpcsvc.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'rpc/rpc-lib/src/rpcsvc.c') diff --git a/rpc/rpc-lib/src/rpcsvc.c b/rpc/rpc-lib/src/rpcsvc.c index 2818f62e619..623523c09d2 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); -- cgit