]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
2556. [cleanup] PCI compliance:
authorMark Andrews <marka@isc.org>
Mon, 16 Feb 2009 02:12:58 +0000 (02:12 +0000)
committerMark Andrews <marka@isc.org>
Mon, 16 Feb 2009 02:12:58 +0000 (02:12 +0000)
                        * 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.

13 files changed:
CHANGES
bin/check/named-checkconf.c
bin/check/named-checkzone.c
bin/named/unix/os.c
lib/dns/rdata/generic/loc_29.c
lib/dns/rdata/generic/soa_6.c
lib/dns/rdata/in_1/wks_11.c
lib/dns/zone.c
lib/isc/include/isc/log.h
lib/isc/log.c
lib/isc/unix/dir.c
lib/isc/unix/file.c
lib/isc/unix/strerror.c

diff --git a/CHANGES b/CHANGES
index 4916f0e35fb0f1248c4cc2027eb4d2fc58f51f15..243ef324129646228f4b08b9729a063112c430b7 100644 (file)
--- 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.
+
 2553.  [bug]           Reference leak on DNSSEC validation errors. [RT #19291]
 
 2552.  [bug]           zero-no-soa-ttl-cache was not being honoured.
index 96efd794661cdf8846add680e5290520546fa49b..d90c28ee603fbd202c80d266387829405175f37e 100644 (file)
@@ -15,7 +15,7 @@
  * PERFORMANCE OF THIS SOFTWARE.
  */
 
-/* $Id: named-checkconf.c,v 1.28.18.16 2007/11/26 23:46:18 tbox Exp $ */
+/* $Id: named-checkconf.c,v 1.28.18.17 2009/02/16 02:12:58 marka Exp $ */
 
 /*! \file */
 
@@ -415,12 +415,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':
index f16053bcbb11aef93c64558ec4030a79c86a1302..82db599bbdf76f0e9e842d054ad29f6cb50e6451 100644 (file)
@@ -15,7 +15,7 @@
  * PERFORMANCE OF THIS SOFTWARE.
  */
 
-/* $Id: named-checkzone.c,v 1.29.18.21 2008/10/24 01:43:17 tbox Exp $ */
+/* $Id: named-checkzone.c,v 1.29.18.22 2009/02/16 02:12:58 marka Exp $ */
 
 /*! \file */
 
@@ -265,12 +265,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':
index f4983b5353d9587fd31d904754fac28fc8c819bc..c7770f5ffa97a65837a2f166eaf74aeb56d6fbf0 100644 (file)
@@ -15,7 +15,7 @@
  * PERFORMANCE OF THIS SOFTWARE.
  */
 
-/* $Id: os.c,v 1.66.18.18 2008/12/01 04:02:15 marka Exp $ */
+/* $Id: os.c,v 1.66.18.19 2009/02/16 02:12:58 marka Exp $ */
 
 /*! \file */
 
@@ -588,7 +588,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);
        }
@@ -597,8 +598,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;
index 026713e82494393c89f15a6bf8e6df5e902021df..1ceef97108e1d42e7c679d2de28502d580962dbe 100644 (file)
@@ -15,7 +15,7 @@
  * PERFORMANCE OF THIS SOFTWARE.
  */
 
-/* $Id: loc_29.c,v 1.41.18.4 2009/01/19 23:46:16 tbox Exp $ */
+/* $Id: loc_29.c,v 1.41.18.5 2009/02/16 02:12:58 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);
index 8de678c581bab694bc570aa7c1c97b135ac08b47..5285f2b53fba942371e78e3723c32911b595437a 100644 (file)
@@ -15,7 +15,7 @@
  * PERFORMANCE OF THIS SOFTWARE.
  */
 
-/* $Id: soa_6.c,v 1.59 2004/03/05 05:10:18 marka Exp $ */
+/* $Id: soa_6.c,v 1.59.18.1 2009/02/16 02:12:58 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));
                }
        }
 
index 749b8fd7fcfe7af26f589d7af0619e2087f61e31..13c696bb080fcb1929e81b00b3d799c648c72c1d 100644 (file)
@@ -15,7 +15,7 @@
  * PERFORMANCE OF THIS SOFTWARE.
  */
 
-/* $Id: wks_11.c,v 1.51.18.1 2004/09/16 01:02:19 marka Exp $ */
+/* $Id: wks_11.c,v 1.51.18.2 2009/02/16 02:12:58 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);
index e4a060da2c0ab1f3be50a66cfc0d4b94fed51010..c1d36efb23693c90bf5d1d26dbe8e6ee9126c6d7 100644 (file)
  * PERFORMANCE OF THIS SOFTWARE.
  */
 
-/* $Id: zone.c,v 1.410.18.57 2009/01/19 23:46:15 tbox Exp $ */
+/* $Id: zone.c,v 1.410.18.58 2009/02/16 02:12:58 marka Exp $ */
 
 /*! \file */
 
 #include <config.h>
+#include <errno.h>
 
 #include <isc/file.h>
 #include <isc/mutex.h>
@@ -29,6 +30,7 @@
 #include <isc/refcount.h>
 #include <isc/rwlock.h>
 #include <isc/serial.h>
+#include <isc/strerror.h>
 #include <isc/string.h>
 #include <isc/taskpool.h>
 #include <isc/timer.h>
@@ -6411,7 +6413,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);
+                       }
                }
        }
 
index 6a746ad75760cee714867d63486ba39024a7d43e..7ac5bfe9bf4c6866a18347602d39aeab47a1e071 100644 (file)
@@ -15,7 +15,7 @@
  * PERFORMANCE OF THIS SOFTWARE.
  */
 
-/* $Id: log.h,v 1.47.18.7 2009/01/19 00:36:28 marka Exp $ */
+/* $Id: log.h,v 1.47.18.8 2009/02/16 02:12:58 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
 
index aaa5a82270e013bbb289a699b792676a5640c02f..9b180b90705fd3ec92d3bffae42c9022e9b947c4 100644 (file)
@@ -15,7 +15,7 @@
  * PERFORMANCE OF THIS SOFTWARE.
  */
 
-/* $Id: log.c,v 1.84.18.12 2009/01/19 00:36:28 marka Exp $ */
+/* $Id: log.c,v 1.84.18.13 2009/02/16 02:12:58 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 }
 };
 
index d4ef88153ea1079bc1b3af2854b99b08fa500c19..3b1378f84c15203528e9968340a4ec8223eeeffe 100644 (file)
@@ -15,7 +15,7 @@
  * PERFORMANCE OF THIS SOFTWARE.
  */
 
-/* $Id: dir.c,v 1.20.18.5 2008/12/01 23:45:57 tbox Exp $ */
+/* $Id: dir.c,v 1.20.18.6 2009/02/16 02:12:58 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);
index e45e0fe68b6c1067d19ac2d07039e49727f4b525..b751fc7ee18ffb9110887f03bb0d91eace0be83f 100644 (file)
@@ -48,7 +48,7 @@
  * SUCH DAMAGE.
  */
 
-/* $Id: file.c,v 1.47.18.2 2005/04/29 00:17:07 marka Exp $ */
+/* $Id: file.c,v 1.47.18.3 2009/02/16 02:12:58 marka Exp $ */
 
 /*! \file */
 
@@ -67,6 +67,7 @@
 
 #include <isc/dir.h>
 #include <isc/file.h>
+#include <isc/log.h>
 #include <isc/random.h>
 #include <isc/string.h>
 #include <isc/time.h>
@@ -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;
index 18cc367e21d65fc3cad7ec4aab5ce959fb5dd347..d7a7e014f98c98a2e2ba294a04957d602f7a0238 100644 (file)
@@ -15,7 +15,7 @@
  * PERFORMANCE OF THIS SOFTWARE.
  */
 
-/* $Id: strerror.c,v 1.4.18.2 2005/04/29 00:17:08 marka Exp $ */
+/* $Id: strerror.c,v 1.4.18.3 2009/02/16 02:12:58 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);