Skip to content

Commit

Permalink
- Make sure that match_address() always restores the "tok" string,
Browse files Browse the repository at this point in the history
  even on error.
- Turned the various FERROR messages into (the more proper) FLOG.
  • Loading branch information
Wayne Davison committed Sep 24, 2004
1 parent fde045c commit be7cf82
Showing 1 changed file with 18 additions and 13 deletions.
31 changes: 18 additions & 13 deletions access.c
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,13 @@ static int match_address(char *addr, char *tok)
/* Fail quietly if tok is a hostname (not an address) */
if (strspn(tok, ".0123456789") != len
#ifdef INET6
&& !strchr(tok, ':')
&& strchr(tok, ':') == NULL
#endif
) return 0;
) {
if (p)
*p = '/';
return 0;
}

memset(&hints, 0, sizeof(hints));
hints.ai_family = PF_UNSPEC;
Expand All @@ -99,17 +103,18 @@ static int match_address(char *addr, char *tok)
hints.ai_flags = AI_NUMERICHOST;
#endif

gai = getaddrinfo(addr, NULL, &hints, &resa);
if (gai) return 0;
if (getaddrinfo(addr, NULL, &hints, &resa) != 0) {
if (p)
*p = '/';
return 0;
}

gai = getaddrinfo(tok, NULL, &hints, &rest);
if (p)
*p++ = '/';
if (gai) {
rprintf(FERROR,
"error matching address %s: %s\n",
tok,
gai_strerror(gai));
if (gai != 0) {
rprintf(FLOG, "error matching address %s: %s\n",
tok, gai_strerror(gai));
freeaddrinfo(resa);
return 0;
}
Expand Down Expand Up @@ -152,7 +157,7 @@ static int match_address(char *addr, char *tok)
}
#endif
default:
rprintf(FERROR,"unknown family %u\n", rest->ai_family);
rprintf(FLOG, "unknown family %u\n", rest->ai_family);
ret = 0;
goto out;
}
Expand All @@ -169,14 +174,14 @@ static int match_address(char *addr, char *tok)
#ifdef HAVE_STRTOL
bits = strtol(p, &ep, 10);
if (!*p || *ep) {
rprintf(FERROR,"malformed mask in %s\n", tok);
rprintf(FLOG, "malformed mask in %s\n", tok);
ret = 0;
goto out;
}
#else
for (pp = (unsigned char *)p; *pp; pp++) {
if (!isascii(*pp) || !isdigit(*pp)) {
rprintf(FERROR,"malformed mask in %s\n", tok);
rprintf(FLOG, "malformed mask in %s\n", tok);
ret = 0;
goto out;
}
Expand All @@ -188,7 +193,7 @@ static int match_address(char *addr, char *tok)
goto out;
}
if (bits < 0 || bits > (addrlen << 3)) {
rprintf(FERROR,"malformed mask in %s\n", tok);
rprintf(FLOG, "malformed mask in %s\n", tok);
ret = 0;
goto out;
}
Expand Down

0 comments on commit be7cf82

Please sign in to comment.