X-Git-Url: http://git.madism.org/?a=blobdiff_plain;f=common%2Frbl.c;h=1f2f44253f09638fcee3c55eca58aad5bc36fa7b;hb=2eddee1ce8e3a644b73e03b65e8d4a3ccd024c76;hp=11ed46415cafa29a49f0727fe28b141452683378;hpb=91da9fe6f37e6a82b226622e1a3e90ee85a9a138;p=apps%2Fpfixtools.git diff --git a/common/rbl.c b/common/rbl.c index 11ed464..1f2f442 100644 --- a/common/rbl.c +++ b/common/rbl.c @@ -38,13 +38,17 @@ static inline rbl_result_t rbl_dns_check(const char *hostname) { + debug("looking up for %s", hostname); struct hostent *host = gethostbyname(hostname); if (host != NULL) { + debug("host found"); return RBL_FOUND; } else { if (h_errno == HOST_NOT_FOUND) { + debug("host not found: %s", hostname); return RBL_NOTFOUND; } + debug("dns error: %m"); return RBL_ERROR; } } @@ -52,15 +56,27 @@ static inline rbl_result_t rbl_dns_check(const char *hostname) rbl_result_t rbl_check(const char *rbl, uint32_t ip) { char host[257]; - snprintf(host, 257, "%d.%d.%d.%d.%s", - ip & 0xff, (ip >> 8) & 0xff, (ip >> 16) & 0xff, (ip >> 24) & 0xff, - rbl); + int len; + + len = snprintf(host, 257, "%d.%d.%d.%d.%s.", + ip & 0xff, (ip >> 8) & 0xff, (ip >> 16) & 0xff, (ip >> 24) & 0xff, + rbl); + if (len >= (int)sizeof(host)) + return RBL_ERROR; + if (host[len - 2] == '.') + host[len - 1] = '\0'; return rbl_dns_check(host); } rbl_result_t rhbl_check(const char *rhbl, const char *hostname) { char host[257]; - snprintf(host, 257, "%s.%s", hostname, rhbl); + int len; + + len = snprintf(host, 257, "%s.%s.", hostname, rhbl); + if (len >= (int)sizeof(host)) + return RBL_ERROR; + if (host[len - 2] == '.') + host[len - 1] = '\0'; return rbl_dns_check(host); }