Changed some names since "depth" wasn't really the right term.
[rsync/rsync.git] / access.c
index d792eaf..4cbd9a1 100644 (file)
--- a/access.c
+++ b/access.c
@@ -51,7 +51,8 @@ static void make_mask(char *mask, int plen, int addrlen) {
 
        if (w)
                memset(mask, 0xff, w);
-       mask[w] = 0xff & (0xff<<(8-b));
+       if (w < addrlen)
+               mask[w] = 0xff & (0xff<<(8-b));
        if (w+1 < addrlen)
                memset(mask+w+1, 0, addrlen-w-1);
 
@@ -78,6 +79,11 @@ static int match_address(char *addr, char *tok)
        p = strchr(tok,'/');
        if (p) *p = 0;
 
+       /* skip if last char is not a digit (i.e. not an address) */
+       /* (don't check first char - might be 11.22.33.44.an.isp) */
+       if (!*tok) return 0;    /* nothing to check */
+       if (!isdigit(*(unsigned char*)tok+strlen(tok)-1)) return 0;
+
        memset(&hints, 0, sizeof(hints));
        hints.ai_family = PF_UNSPEC;
        hints.ai_socktype = SOCK_STREAM;
@@ -121,6 +127,8 @@ static int match_address(char *addr, char *tok)
                a = (char *)&sin6a->sin6_addr;
                t = (char *)&sin6t->sin6_addr;
 
+               addrlen = 16;
+
 #ifdef HAVE_SOCKADDR_IN6_SCOPE_ID
                if (sin6t->sin6_scope_id &&
                    sin6a->sin6_scope_id != sin6t->sin6_scope_id) {
@@ -129,10 +137,6 @@ static int match_address(char *addr, char *tok)
                }
 #endif
 
-               a = (char *)&sin6a->sin6_addr;
-               t = (char *)&sin6t->sin6_addr;
-               addrlen = 16;
-
                break;
            }
 #endif