]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
[v9_8] null terminate strings for coverity
authorEvan Hunt <each@isc.org>
Mon, 16 Jun 2014 22:31:25 +0000 (15:31 -0700)
committerEvan Hunt <each@isc.org>
Mon, 16 Jun 2014 22:31:25 +0000 (15:31 -0700)
bin/dig/dig.c
bin/tests/system/dlzexternal/driver.c
contrib/dlz/example/dlz_example.c
lib/dns/gen.c
lib/dns/rcode.c
lib/lwres/getaddrinfo.c

index f2317b4c5e6f74a7e6489c120cb48f39aff7cf9c..99dc199e20657857460b931e68060c348de797b3 100644 (file)
@@ -1396,6 +1396,7 @@ dash_option(char *option, char *next, dig_lookup_t **lookup,
                                ip6_int, ISC_FALSE) == ISC_R_SUCCESS) {
                        strncpy((*lookup)->textname, textname,
                                sizeof((*lookup)->textname));
+                       (*lookup)->textname[sizeof((*lookup)->textname)-1] = 0;
                        debug("looking up %s", (*lookup)->textname);
                        (*lookup)->trace_root = ISC_TF((*lookup)->trace  ||
                                                (*lookup)->ns_search_only);
index 7f52c0ed76cbe5dfbe1843547481168da6af50b8..e91d26e501260a530abc1fbeedfaccc5ee627678 100644 (file)
@@ -135,8 +135,14 @@ add_name(struct dlz_example_data *state, struct record *list,
                return (ISC_R_NOSPACE);
 
        strncpy(list[i].name, name, sizeof(list[i].name));
+       list[i].name[sizeof(list[i].name) - 1] = '\0';
+
        strncpy(list[i].type, type, sizeof(list[i].type));
+       list[i].type[sizeof(list[i].type) - 1] = '\0';
+
        strncpy(list[i].data, data, sizeof(list[i].data));
+       list[i].data[sizeof(list[i].data) - 1] = '\0';
+
        list[i].ttl = ttl;
 
        return (ISC_R_SUCCESS);
index f188be821d1d4466ec01ee41a847beb1383f09b8..9a47c007cadd15e15ea092436fc35ccfd7bd7919 100644 (file)
@@ -118,8 +118,14 @@ static isc_result_t add_name(struct dlz_example_data *state,
                return (ISC_R_NOSPACE);
 
        strncpy(list[i].name, name, sizeof(list[i].name));
+       list[i].name[sizeof(list[i].name) - 1] = '\0';
+
        strncpy(list[i].type, type, sizeof(list[i].type));
+       list[i].type[sizeof(list[i].type) - 1] = '\0';
+
        strncpy(list[i].data, data, sizeof(list[i].data));
+       list[i].data[sizeof(list[i].data) - 1] = '\0';
+
        list[i].ttl = ttl;
 
        return (ISC_R_SUCCESS);
index b934c9990fb3f55674a37b6d683518def256401c..4fea096c35a30099a57124f860477ca41128c783 100644 (file)
@@ -331,15 +331,20 @@ insert_into_typenames(int type, const char *typename, const char *attr) {
                exit(1);
        }
 
+       /* XXXMUKS: This is redundant due to the INSIST above. */
        if (strlen(typename) > sizeof(ttn->typename) - 1) {
                fprintf(stderr, "Error:  type name %s is too long\n",
                        typename);
                exit(1);
        }
+
        strncpy(ttn->typename, typename, sizeof(ttn->typename));
-       ttn->type = type;
+       ttn->typename[sizeof(ttn->typename) - 1] = '\0';
 
        strncpy(ttn->macroname, ttn->typename, sizeof(ttn->macroname));
+       ttn->macroname[sizeof(ttn->macroname) - 1] = '\0';
+
+       ttn->type = type;
        c = strlen(ttn->macroname);
        while (c > 0) {
                if (ttn->macroname[c - 1] == '-')
@@ -365,7 +370,10 @@ insert_into_typenames(int type, const char *typename, const char *attr) {
                        attr, typename);
                exit(1);
        }
+
        strncpy(ttn->attr, attr, sizeof(ttn->attr));
+       ttn->attr[sizeof(ttn->attr) - 1] = '\0';
+
        ttn->sorted = 0;
        if (maxtype < type)
                maxtype = type;
@@ -394,11 +402,17 @@ add(int rdclass, const char *classname, int type, const char *typename,
        newtt->next = NULL;
        newtt->rdclass = rdclass;
        newtt->type = type;
+
        strncpy(newtt->classname, classname, sizeof(newtt->classname));
+       newtt->classname[sizeof(newtt->classname) - 1] = '\0';
+
        strncpy(newtt->typename, typename, sizeof(newtt->typename));
+       newtt->typename[sizeof(newtt->typename) - 1] = '\0';
+
        if (strncmp(dirname, "./", 2) == 0)
                dirname += 2;
        strncpy(newtt->dirname, dirname, sizeof(newtt->dirname));
+       newtt->dirname[sizeof(newtt->dirname) - 1] = '\0';
 
        tt = types;
        oldtt = NULL;
index 69007f881efdfd90bfe230768d2b1afee84a4e54..2fdb751e6dbf16bdd96c52176af9527f9e465c31 100644 (file)
@@ -212,11 +212,13 @@ maybe_numeric(unsigned int *valuep, isc_textregion_t *source,
                return (ISC_R_BADNUMBER);
 
        /*
-        * We have a potential number.  Try to parse it with
-        * isc_parse_uint32().  isc_parse_uint32() requires
+        * We have a potential number.  Try to parse it with
+        * isc_parse_uint32().  isc_parse_uint32() requires
         * null termination, so we must make a copy.
         */
-       strncpy(buffer, source->base, NUMBERSIZE);
+       strncpy(buffer, source->base, sizeof(buffer));
+       buffer[sizeof(buffer) - 1] = '\0';
+
        INSIST(buffer[source->length] == '\0');
 
        result = isc_parse_uint32(&n, buffer, 10);
index 1ebafd85a6788996848d5b4bc0bb2748c9996d78..43211fd07c2bc8e60e462b20ca60d9f06e7419e1 100644 (file)
@@ -706,12 +706,16 @@ get_local(const char *name, int socktype, struct addrinfo **res) {
        if (socktype == 0)
                return (EAI_SOCKTYPE);
 
+       if (strlen(name) >= sizeof(slocal->sun_path))
+               return (EAI_OVERFLOW);
+
        ai = ai_alloc(AF_LOCAL, sizeof(*slocal));
        if (ai == NULL)
                return (EAI_MEMORY);
 
        slocal = SLOCAL(ai->ai_addr);
        strncpy(slocal->sun_path, name, sizeof(slocal->sun_path));
+       slocal->sun_path[sizeof(slocal->sun_path) - 1] = '\0';
 
        ai->ai_socktype = socktype;
        /*