Improve ipmask_parse()'s handling of invalid IPv6 inputs.
[ircu2.10.12-pk.git] / ircd / ircd_string.c
index 1ed082d6f34d6073d5d5d59041b4d8d65c7ad99a..f27db15c4b4184bcfba87731b0f0e873b5ce9d14 100644 (file)
@@ -481,9 +481,11 @@ ircd_aton_ip4(const char *input, unsigned int *output, unsigned char *pbits)
       *pbits = bits;
     return pos;
   case '.':
+    if (++dots > 3)
+      return 0;
     if (input[++pos] == '.')
       return 0;
-    ip |= part << (24 - 8 * dots++);
+    ip |= part << (32 - 8 * dots);
     part = 0;
     if (input[pos] == '*') {
       while (input[++pos] == '*' || input[pos] == '.') ;
@@ -620,6 +622,8 @@ ipmask_parse(const char *input, struct irc_in_addr *ip, unsigned char *pbits)
     default:
       return 0;
     }
+    if (input[pos] != '\0')
+      return 0;
   finish:
     if (colon < 8) {
       unsigned int jj;