]> git.proxmox.com Git - mirror_kronosnet.git/commitdiff
misc: some coverity fixes
authorChristine Caulfield <ccaulfie@redhat.com>
Fri, 17 May 2019 07:44:08 +0000 (08:44 +0100)
committerFabio M. Di Nitto <fdinitto@redhat.com>
Mon, 20 May 2019 11:38:32 +0000 (13:38 +0200)
In rough order of seriousness:

1. Fix clock_gettime() in pmtud so that it's always called, as
   variable 'clock_now' is always read.
2. Allow space for trailing NUL in libnozzle device names
3. Fix api_nozzle_run_updown_test so it can run out of the build tree
4. Disallow a 0 length prefix in libnozzle
5. Fix potential use of NULL pointer on doxyxml
6. Free 'name' in doxyxml as it's *not* in the map any more
7. Fix dead code in libknet API functions left by code changes

libknet/handle.c
libknet/host.c
libknet/threads_pmtud.c
libnozzle/internals.c
libnozzle/libnozzle.c
libnozzle/tests/api_nozzle_run_updown.c
man/doxyxml.c

index 0a2f75aef96a219927843e389369f90b8873a75d..268d6106abe5c962f0048f828373beb261d62384 100644 (file)
@@ -785,7 +785,7 @@ int knet_handle_enable_sock_notify(knet_handle_t knet_h,
                                                int error,
                                                int errorno))
 {
-       int savederrno = 0, err = 0;
+       int savederrno = 0;
 
        if (!knet_h) {
                errno = EINVAL;
@@ -811,8 +811,7 @@ int knet_handle_enable_sock_notify(knet_handle_t knet_h,
 
        pthread_rwlock_unlock(&knet_h->global_rwlock);
 
-       errno = err ? savederrno : 0;
-       return err;
+       return 0;
 }
 
 int knet_handle_add_datafd(knet_handle_t knet_h, int *datafd, int8_t *channel)
@@ -1576,7 +1575,6 @@ out_unlock:
 int knet_handle_get_stats(knet_handle_t knet_h, struct knet_handle_stats *stats, size_t struct_size)
 {
        int savederrno = 0;
-       int err = 0;
 
        if (!knet_h) {
                errno = EINVAL;
@@ -1616,14 +1614,12 @@ int knet_handle_get_stats(knet_handle_t knet_h, struct knet_handle_stats *stats,
        stats->size = sizeof(struct knet_handle_stats);
 
        pthread_rwlock_unlock(&knet_h->global_rwlock);
-       errno = err ? savederrno : 0;
-       return err;
+       return 0;
 }
 
 int knet_handle_clear_stats(knet_handle_t knet_h, int clear_option)
 {
        int savederrno = 0;
-       int err = 0;
 
        if (!knet_h) {
                errno = EINVAL;
@@ -1651,7 +1647,6 @@ int knet_handle_clear_stats(knet_handle_t knet_h, int clear_option)
        }
 
        pthread_rwlock_unlock(&knet_h->global_rwlock);
-       errno = err ? savederrno : 0;
-       return err;
+       return 0;
 }
 
index 480db73329bdead10a6d682f6a6f9af5f11fc098..66826c1a196f0dde4438306accfbe02e697d30e2 100644 (file)
@@ -331,7 +331,7 @@ int knet_host_get_id_by_host_name(knet_handle_t knet_h, const char *name,
 int knet_host_get_host_list(knet_handle_t knet_h,
                            knet_node_id_t *host_ids, size_t *host_ids_entries)
 {
-       int savederrno = 0, err = 0;
+       int savederrno = 0;
 
        if (!knet_h) {
                errno = EINVAL;
@@ -355,8 +355,7 @@ int knet_host_get_host_list(knet_handle_t knet_h,
        *host_ids_entries = knet_h->host_ids_entries;
 
        pthread_rwlock_unlock(&knet_h->global_rwlock);
-       errno = err ? savederrno : 0;
-       return err;
+       return 0;
 }
 
 int knet_host_set_policy(knet_handle_t knet_h, knet_node_id_t host_id,
index 005055742c8eb3f10ec339637a4e1a1634b93164..c5a2b2762b408c3dbc01fe85546ccf751313d3ef 100644 (file)
@@ -380,14 +380,14 @@ static int _handle_check_pmtud(knet_handle_t knet_h, struct knet_host *dst_host,
        struct timespec clock_now;
        unsigned long long diff_pmtud, interval;
 
+       if (clock_gettime(CLOCK_MONOTONIC, &clock_now) != 0) {
+               log_debug(knet_h, KNET_SUB_PMTUD, "Unable to get monotonic clock");
+               return 0;
+       }
+
        if (!force_run) {
                interval = knet_h->pmtud_interval * 1000000000llu; /* nanoseconds */
 
-               if (clock_gettime(CLOCK_MONOTONIC, &clock_now) != 0) {
-                       log_debug(knet_h, KNET_SUB_PMTUD, "Unable to get monotonic clock");
-                       return 0;
-               }
-
                timespec_diff(dst_link->pmtud_last, clock_now, &diff_pmtud);
 
                if (diff_pmtud < interval) {
index 6e683463978248a840de8b15236466301f912119..f056e3bf4a3264bfc511d09de4b904186be25b57 100644 (file)
@@ -144,7 +144,7 @@ char *generate_v4_broadcast(const char *ipaddr, const char *prefix)
 
        prefix_len = atoi(prefix);
 
-       if ((prefix_len > 32) || (prefix_len < 0))
+       if ((prefix_len > 32) || (prefix_len <= 0))
                return NULL;
 
        if (inet_pton(AF_INET, ipaddr, &address) <= 0)
index 4e5a2d40e08a62fbaf0aca905cd2dbf59be1bfa0..b6e95666892dfb47f56434dac689a04d4c7a331a 100644 (file)
@@ -405,7 +405,8 @@ nozzle_t nozzle_open(char *devname, size_t devname_size, const char *updownpath)
                return NULL;
        }
 
-       if (strlen(devname) > IFNAMSIZ) {
+       /* Need to allow space for trailing NUL */
+       if (strlen(devname) >= IFNAMSIZ) {
                errno = E2BIG;
                return NULL;
        }
index a078ad7c1a8e3bafac772ab39e05e0a2620174a7..c80216a27e7fc42f2391e5750133f5f51b747de1 100644 (file)
@@ -29,16 +29,21 @@ static int test(void)
        nozzle_t nozzle = NULL;
        char *error_string = NULL;
        char *tmpdir = NULL;
-       char tmpdirsrc[PATH_MAX];
+       char tmpdirsrc[PATH_MAX*2];
        char tmpstr[PATH_MAX*2];
        char srcfile[PATH_MAX];
        char dstfile[PATH_MAX];
+       char current_dir[PATH_MAX];
 
        /*
         * create a tmp dir for storing up/down scripts.
         * we cannot create symlinks src dir
         */
-       strcpy(tmpdirsrc, ABSBUILDDIR "/nozzle_test_XXXXXX");
+       if (getcwd(current_dir, sizeof(current_dir)) == NULL) {
+               printf("Unable to get current working directory: %s\n", strerror(errno));
+               return -1;
+       }
+       snprintf(tmpdirsrc, sizeof(tmpdirsrc)-1, "%s/nozzle_test_XXXXXX", current_dir);
 
        tmpdir = mkdtemp(tmpdirsrc);
        if (!tmpdir) {
index b623711dc706b5a76a70cf37f57a6a46f4a423c0..7d9a60c76613ee72fd2988d3f6ffc26dcb19b16f 100644 (file)
@@ -695,17 +695,17 @@ static void collect_enums(xmlNode *cur_node, void *arg)
                                }
                        }
 
-                       si = malloc(sizeof(struct struct_info));
-                       if (si) {
-                               si->kind = STRUCTINFO_ENUM;
-                               qb_list_init(&si->params_list);
-                               si->structname = strdup(name);
-                               traverse_node(cur_node, "enumvalue", read_struct, si);
-                               qb_map_put(structures_map, refid, si);
+                       if (name) {
+                               si = malloc(sizeof(struct struct_info));
+                               if (si) {
+                                       si->kind = STRUCTINFO_ENUM;
+                                       qb_list_init(&si->params_list);
+                                       si->structname = strdup(name);
+                                       traverse_node(cur_node, "enumvalue", read_struct, si);
+                                       qb_map_put(structures_map, refid, si);
+                               }
                        }
-
                }
-
        }
 }
 
@@ -786,7 +786,7 @@ static void traverse_members(xmlNode *cur_node, void *arg)
                free(kind);
                free(def);
                free(args);
-//             free(name); /* don't free, it's in the map */
+               free(name);
        }
 }