]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
2556. [cleanup] PCI compliance:
authorMark Andrews <marka@isc.org>
Mon, 16 Feb 2009 02:01:16 +0000 (02:01 +0000)
committerMark Andrews <marka@isc.org>
Mon, 16 Feb 2009 02:01:16 +0000 (02:01 +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 11d16ff39470731125b10c232fd424fb15bbe504..41ab1f51b2a95588b560b89b79f561f15747fc74 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.
+
 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]
index 0c6e70f96cabe0a7982029089f4a9d66cbdd9d47..22eb6b52224286459d3d6e3554fedeeb24e8363f 100644 (file)
@@ -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':
index 60f1ee2ded5d37e2617fb2b9e179748c91b35515..02df7c605ca87bf00c898b6ae1b3caeb9a79c436 100644 (file)
@@ -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':
index f0ae1fcc47ecb372d271a12c53e1a9507eaf594d..8619c71a5dc1b14bf164f32ce3036c5a90efc50b 100644 (file)
@@ -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;
index 7d04e9a7d7ca2ca4aeee8bfefa1456fe30ebbd4c..bc99797b624275c07b3399cdc6f421ac00574755 100644 (file)
@@ -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);
index b135adf29f9e644deb31cd786f6b10b1e12fa7a6..c52641c7e706ee6c383decd1ed93e9611b2cb014 100644 (file)
@@ -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));
                }
        }
 
index fca90110fec70109c51b2cd485e52a3c1551a50a..813e46f8b03efe95183351211c530360b26a243e 100644 (file)
@@ -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);
index 5001ebcb2fe75b9437606e0e66f6f22f679e2b9a..2b90b9e7875f4f58e6c69aa68598506645bd3631 100644 (file)
  * 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 <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/stats.h>
 #include <isc/stdtime.h>
 #include <isc/string.h>
@@ -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);
+                       }
                }
        }
 
index 17818e8673d6d097a1f4cbc7407fa822c326547b..741c5324290c0af082dcb3ede05dfa273b944b7f 100644 (file)
@@ -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
 
index 43ee80977d03be07ab30050c203202db6f08447a..79ca4f2a4008a22454fdd0528146ad91f60fe031 100644 (file)
@@ -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 }
 };
 
index 5adff6a75e6af9de0d35fe7e374383dcc95fbc77..cd0e30cbb59ca10375ba1b67cf5327885b3357e5 100644 (file)
@@ -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);
index c5731c64f662dc0e80467efa12cd0a4879d41cba..958a0cea822e5ceeac7f491b00691ef23a1949cb 100644 (file)
@@ -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 <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 42a7a8eb50483e7fa132abcd180506add5fb7798..317c4f1a263c7f998c8d1b66b1bf2e9668ebfedc 100644 (file)
@@ -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);