diff --git a/CHANGES b/CHANGES index 11d16ff394..41ab1f51b2 100644 --- a/CHANGES +++ b/CHANGES @@ -1,3 +1,10 @@ +2556. [cleanup] PCI compliance: + * new libisc log module file + * isc_dir_chroot() now also changes the working + directory to "/". + * additional INSISTs + * additional logging when files can't be removed. + 2555. [port] Solaris: mkdir(2) on tmpfs filesystems does not do the error checks in the correct order resulting in the wrong error code sometimes being returned. [RT #19249] diff --git a/bin/check/named-checkconf.c b/bin/check/named-checkconf.c index 0c6e70f96c..22eb6b5222 100644 --- a/bin/check/named-checkconf.c +++ b/bin/check/named-checkconf.c @@ -15,7 +15,7 @@ * PERFORMANCE OF THIS SOFTWARE. */ -/* $Id: named-checkconf.c,v 1.46 2007/11/26 02:12:45 marka Exp $ */ +/* $Id: named-checkconf.c,v 1.47 2009/02/16 02:01:15 marka Exp $ */ /*! \file */ @@ -419,12 +419,6 @@ main(int argc, char **argv) { isc_result_totext(result)); exit(1); } - result = isc_dir_chdir("/"); - if (result != ISC_R_SUCCESS) { - fprintf(stderr, "isc_dir_chdir: %s\n", - isc_result_totext(result)); - exit(1); - } break; case 'v': diff --git a/bin/check/named-checkzone.c b/bin/check/named-checkzone.c index 60f1ee2ded..02df7c605c 100644 --- a/bin/check/named-checkzone.c +++ b/bin/check/named-checkzone.c @@ -15,7 +15,7 @@ * PERFORMANCE OF THIS SOFTWARE. */ -/* $Id: named-checkzone.c,v 1.51 2008/10/24 01:44:48 tbox Exp $ */ +/* $Id: named-checkzone.c,v 1.52 2009/02/16 02:01:15 marka Exp $ */ /*! \file */ @@ -268,12 +268,6 @@ main(int argc, char **argv) { isc_result_totext(result)); exit(1); } - result = isc_dir_chdir("/"); - if (result != ISC_R_SUCCESS) { - fprintf(stderr, "isc_dir_chdir: %s\n", - isc_result_totext(result)); - exit(1); - } break; case 's': diff --git a/bin/named/unix/os.c b/bin/named/unix/os.c index f0ae1fcc47..8619c71a5d 100644 --- a/bin/named/unix/os.c +++ b/bin/named/unix/os.c @@ -15,7 +15,7 @@ * PERFORMANCE OF THIS SOFTWARE. */ -/* $Id: os.c,v 1.91 2009/02/16 00:13:02 marka Exp $ */ +/* $Id: os.c,v 1.92 2009/02/16 02:01:15 marka Exp $ */ /*! \file */ @@ -645,7 +645,8 @@ safe_open(const char *filename, isc_boolean_t append) { fd = open(filename, O_WRONLY|O_CREAT|O_APPEND, S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH); else { - (void)unlink(filename); + if (unlink(filename) < 0 && errno != ENOENT) + return (-1); fd = open(filename, O_WRONLY|O_CREAT|O_EXCL, S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH); } @@ -654,8 +655,11 @@ safe_open(const char *filename, isc_boolean_t append) { static void cleanup_pidfile(void) { + int n; if (pidfile != NULL) { - (void)unlink(pidfile); + n = unlink(pidfile); + if (n == -1 && errno != ENOENT) + ns_main_earlywarning("unlink '%s': failed", pidfile); free(pidfile); } pidfile = NULL; diff --git a/lib/dns/rdata/generic/loc_29.c b/lib/dns/rdata/generic/loc_29.c index 7d04e9a7d7..bc99797b62 100644 --- a/lib/dns/rdata/generic/loc_29.c +++ b/lib/dns/rdata/generic/loc_29.c @@ -15,7 +15,7 @@ * PERFORMANCE OF THIS SOFTWARE. */ -/* $Id: loc_29.c,v 1.47 2009/01/17 23:47:43 tbox Exp $ */ +/* $Id: loc_29.c,v 1.48 2009/02/16 02:01:16 marka Exp $ */ /* Reviewed: Wed Mar 15 18:13:09 PST 2000 by explorer */ @@ -482,16 +482,19 @@ totext_loc(ARGS_TOTEXT) { /* version = sr.base[0]; */ size = sr.base[1]; + INSIST((size&0x0f) < 10 && (size>>4) < 10); if ((size&0x0f)> 1) sprintf(sbuf, "%lum", (size>>4) * poweroften[(size&0x0f)-2]); else sprintf(sbuf, "0.%02lum", (size>>4) * poweroften[(size&0x0f)]); hp = sr.base[2]; + INSIST((hp&0x0f) < 10 && (hp>>4) < 10); if ((hp&0x0f)> 1) sprintf(hbuf, "%lum", (hp>>4) * poweroften[(hp&0x0f)-2]); else sprintf(hbuf, "0.%02lum", (hp>>4) * poweroften[(hp&0x0f)]); vp = sr.base[3]; + INSIST((vp&0x0f) < 10 && (vp>>4) < 10); if ((vp&0x0f)> 1) sprintf(vbuf, "%lum", (vp>>4) * poweroften[(vp&0x0f)-2]); else @@ -514,6 +517,7 @@ totext_loc(ARGS_TOTEXT) { m1 = (int)(latitude % 60); latitude /= 60; d1 = (int)latitude; + INSIST(latitude <= 90); longitude = uint32_fromregion(&sr); isc_region_consume(&sr, 4); @@ -531,6 +535,7 @@ totext_loc(ARGS_TOTEXT) { m2 = (int)(longitude % 60); longitude /= 60; d2 = (int)longitude; + INSIST(longitude <= 180); altitude = uint32_fromregion(&sr); isc_region_consume(&sr, 4); diff --git a/lib/dns/rdata/generic/soa_6.c b/lib/dns/rdata/generic/soa_6.c index b135adf29f..c52641c7e7 100644 --- a/lib/dns/rdata/generic/soa_6.c +++ b/lib/dns/rdata/generic/soa_6.c @@ -15,7 +15,7 @@ * PERFORMANCE OF THIS SOFTWARE. */ -/* $Id: soa_6.c,v 1.61 2007/06/19 23:47:17 tbox Exp $ */ +/* $Id: soa_6.c,v 1.62 2009/02/16 02:01:16 marka Exp $ */ /* Reviewed: Thu Mar 16 15:18:32 PST 2000 by explorer */ @@ -101,7 +101,11 @@ totext_soa(ARGS_TOTEXT) { REQUIRE(rdata->length != 0); multiline = ISC_TF((tctx->flags & DNS_STYLEFLAG_MULTILINE) != 0); - comment = ISC_TF((tctx->flags & DNS_STYLEFLAG_COMMENT) != 0); + if (multiline) + comment = ISC_TF((tctx->flags & DNS_STYLEFLAG_COMMENT) != 0); + else + comment = ISC_FALSE; + dns_name_init(&mname, NULL); dns_name_init(&rname, NULL); @@ -128,16 +132,13 @@ totext_soa(ARGS_TOTEXT) { RETERR(str_totext(tctx->linebreak, target)); for (i = 0; i < 5; i++) { - char buf[sizeof("2147483647")]; + char buf[sizeof("0123456789 ; ")]; unsigned long num; - unsigned int numlen; num = uint32_fromregion(&dregion); isc_region_consume(&dregion, 4); - numlen = sprintf(buf, "%lu", num); - INSIST(numlen > 0 && numlen < sizeof("2147483647")); + sprintf(buf, comment ? "%-10lu ; " : "%lu", num); RETERR(str_totext(buf, target)); - if (multiline && comment) { - RETERR(str_totext(" ; " + numlen, target)); + if (comment) { RETERR(str_totext(soa_fieldnames[i], target)); /* Print times in week/day/hour/minute/second form */ if (i >= 1) { @@ -147,7 +148,7 @@ totext_soa(ARGS_TOTEXT) { } RETERR(str_totext(tctx->linebreak, target)); } else if (i < 4) { - RETERR(str_totext(tctx->linebreak, target)); + RETERR(str_totext(tctx->linebreak, target)); } } diff --git a/lib/dns/rdata/in_1/wks_11.c b/lib/dns/rdata/in_1/wks_11.c index fca90110fe..813e46f8b0 100644 --- a/lib/dns/rdata/in_1/wks_11.c +++ b/lib/dns/rdata/in_1/wks_11.c @@ -15,7 +15,7 @@ * PERFORMANCE OF THIS SOFTWARE. */ -/* $Id: wks_11.c,v 1.54 2007/06/19 23:47:17 tbox Exp $ */ +/* $Id: wks_11.c,v 1.55 2009/02/16 02:01:16 marka Exp $ */ /* Reviewed: Fri Mar 17 15:01:49 PST 2000 by explorer */ @@ -158,6 +158,7 @@ totext_in_wks(ARGS_TOTEXT) { RETERR(str_totext(buf, target)); isc_region_consume(&sr, 1); + INSIST(sr.length <= 8*1024); for (i = 0; i < sr.length; i++) { if (sr.base[i] != 0) for (j = 0; j < 8; j++) @@ -242,7 +243,8 @@ fromstruct_in_wks(ARGS_FROMSTRUCT) { REQUIRE(source != NULL); REQUIRE(wks->common.rdtype == type); REQUIRE(wks->common.rdclass == rdclass); - REQUIRE(wks->map != NULL || wks->map_len == 0); + REQUIRE((wks->map != NULL && wks->map_len <= 8*1024) || + wks->map_len == 0); UNUSED(type); UNUSED(rdclass); diff --git a/lib/dns/zone.c b/lib/dns/zone.c index 5001ebcb2f..2b90b9e787 100644 --- a/lib/dns/zone.c +++ b/lib/dns/zone.c @@ -15,11 +15,12 @@ * PERFORMANCE OF THIS SOFTWARE. */ -/* $Id: zone.c,v 1.486 2009/01/27 22:29:59 jinmei Exp $ */ +/* $Id: zone.c,v 1.487 2009/02/16 02:01:15 marka Exp $ */ /*! \file */ #include +#include #include #include @@ -29,6 +30,7 @@ #include #include #include +#include #include #include #include @@ -9556,7 +9558,17 @@ zone_replacedb(dns_zone_t *zone, dns_db_t *db, isc_boolean_t dump) { isc_log_write(dns_lctx, DNS_LOGCATEGORY_GENERAL, DNS_LOGMODULE_ZONE, ISC_LOG_DEBUG(3), "removing journal file"); - (void)remove(zone->journal); + if (remove(zone->journal) < 0) { + char strbuf[ISC_STRERRORSIZE]; + isc__strerror(errno, strbuf, sizeof(strbuf)); + isc_log_write(dns_lctx, + DNS_LOGCATEGORY_GENERAL, + DNS_LOGMODULE_ZONE, + ISC_LOG_WARNING, + "unable to remove journal " + "'%s': '%s'", + zone->journal, strbuf); + } } } diff --git a/lib/isc/include/isc/log.h b/lib/isc/include/isc/log.h index 17818e8673..741c532429 100644 --- a/lib/isc/include/isc/log.h +++ b/lib/isc/include/isc/log.h @@ -15,7 +15,7 @@ * PERFORMANCE OF THIS SOFTWARE. */ -/* $Id: log.h,v 1.58 2009/01/17 23:19:14 fdupont Exp $ */ +/* $Id: log.h,v 1.59 2009/02/16 02:01:16 marka Exp $ */ #ifndef ISC_LOG_H #define ISC_LOG_H 1 @@ -166,6 +166,7 @@ LIBISC_EXTERNAL_DATA extern isc_logmodule_t isc_modules[]; #define ISC_LOGMODULE_TIME (&isc_modules[1]) #define ISC_LOGMODULE_INTERFACE (&isc_modules[2]) #define ISC_LOGMODULE_TIMER (&isc_modules[3]) +#define ISC_LOGMODULE_FILE (&isc_modules[4]) ISC_LANG_BEGINDECLS diff --git a/lib/isc/log.c b/lib/isc/log.c index 43ee80977d..79ca4f2a40 100644 --- a/lib/isc/log.c +++ b/lib/isc/log.c @@ -15,7 +15,7 @@ * PERFORMANCE OF THIS SOFTWARE. */ -/* $Id: log.c,v 1.98 2009/01/18 00:41:42 fdupont Exp $ */ +/* $Id: log.c,v 1.99 2009/02/16 02:01:16 marka Exp $ */ /*! \file * \author Principal Authors: DCL */ @@ -204,6 +204,7 @@ LIBISC_EXTERNAL_DATA isc_logmodule_t isc_modules[] = { { "time", 0 }, { "interface", 0 }, { "timer", 0 }, + { "file", 0 }, { NULL, 0 } }; diff --git a/lib/isc/unix/dir.c b/lib/isc/unix/dir.c index 5adff6a75e..cd0e30cbb5 100644 --- a/lib/isc/unix/dir.c +++ b/lib/isc/unix/dir.c @@ -15,7 +15,7 @@ * PERFORMANCE OF THIS SOFTWARE. */ -/* $Id: dir.c,v 1.27 2008/12/01 23:47:45 tbox Exp $ */ +/* $Id: dir.c,v 1.28 2009/02/16 02:01:16 marka Exp $ */ /*! \file * \author Principal Authors: DCL */ @@ -172,7 +172,7 @@ isc_dir_chroot(const char *dirname) { REQUIRE(dirname != NULL); #ifdef HAVE_CHROOT - if (chroot(dirname) < 0) + if (chroot(dirname) < 0 || chdir("/") < 0) return (isc__errno2result(errno)); return (ISC_R_SUCCESS); diff --git a/lib/isc/unix/file.c b/lib/isc/unix/file.c index c5731c64f6..958a0cea82 100644 --- a/lib/isc/unix/file.c +++ b/lib/isc/unix/file.c @@ -48,7 +48,7 @@ * SUCH DAMAGE. */ -/* $Id: file.c,v 1.51 2007/06/19 23:47:18 tbox Exp $ */ +/* $Id: file.c,v 1.52 2009/02/16 02:01:16 marka Exp $ */ /*! \file */ @@ -67,6 +67,7 @@ #include #include +#include #include #include #include @@ -235,7 +236,9 @@ isc_file_renameunique(const char *file, char *templet) { } } } - (void)unlink(file); + if (unlink(file) < 0) + if (errno != ENOENT) + return (isc__errno2result(errno)); return (ISC_R_SUCCESS); } @@ -287,7 +290,11 @@ isc_file_openunique(char *templet, FILE **fp) { f = fdopen(fd, "w+"); if (f == NULL) { result = isc__errno2result(errno); - (void)remove(templet); + if (remove(templet) < 0) { + isc_log_write(isc_lctx, ISC_LOGCATEGORY_GENERAL, + ISC_LOGMODULE_FILE, ISC_LOG_ERROR, + "remove '%s': failed", templet); + } (void)close(fd); } else *fp = f; diff --git a/lib/isc/unix/strerror.c b/lib/isc/unix/strerror.c index 42a7a8eb50..317c4f1a26 100644 --- a/lib/isc/unix/strerror.c +++ b/lib/isc/unix/strerror.c @@ -15,7 +15,7 @@ * PERFORMANCE OF THIS SOFTWARE. */ -/* $Id: strerror.c,v 1.8 2007/06/19 23:47:18 tbox Exp $ */ +/* $Id: strerror.c,v 1.9 2009/02/16 02:01:16 marka Exp $ */ /*! \file */ @@ -47,7 +47,7 @@ void isc__strerror(int num, char *buf, size_t size) { #ifdef HAVE_STRERROR char *msg; - unsigned int unum = num; + unsigned int unum = (unsigned int)num; static isc_once_t once = ISC_ONCE_INIT; REQUIRE(buf != NULL); @@ -62,7 +62,7 @@ isc__strerror(int num, char *buf, size_t size) { snprintf(buf, size, "Unknown error: %u", unum); UNLOCK(&isc_strerror_lock); #else - unsigned int unum = num; + unsigned int unum = (unsigned int)num; REQUIRE(buf != NULL);