diff --git a/lib/rpc_subs.c b/lib/rpc_subs.c
index 2c5b5d5..5151a1e 100644
--- a/lib/rpc_subs.c
+++ b/lib/rpc_subs.c
@@ -1072,18 +1072,23 @@ static char *inet_fill_net(const char *net_num, char *net)
if (strlen(net_num) > INET_ADDRSTRLEN)
return NULL;
+ if (!isdigit(*net_num))
+ return NULL;
+
*net = '\0';
strcpy(net, net_num);
np = net;
- while (*np) {
- if (*np++ == '.') {
+ while (*np++) {
+ if (*np == '.') {
+ np++;
dots--;
if (!*np && dots)
strcat(net, "0");
+ continue;
}
- if (!isdigit(*np) || dots < 0) {
+ if ((*np && !isdigit(*np)) || dots < 0) {
*net = '\0';
return NULL;
}