]> git.proxmox.com Git - mirror_kronosnet.git/commitdiff
[host] fix knet_host_set_name api checks
authorFabio M. Di Nitto <fdinitto@redhat.com>
Mon, 20 Jun 2016 04:51:27 +0000 (06:51 +0200)
committerFabio M. Di Nitto <fdinitto@redhat.com>
Mon, 20 Jun 2016 04:51:27 +0000 (06:51 +0200)
verify that we actually get a name from the caller
and make sure name is unique or search would break

Signed-off-by: Fabio M. Di Nitto <fdinitto@redhat.com>
libknet/host.c
libknet/libknet.h

index c83a80959334efd4146a516b845017a8c8f644cb..aae2966a7c42de455ce91cb210268290b8f6cfcb 100644 (file)
@@ -202,6 +202,7 @@ exit_unlock:
 int knet_host_set_name(knet_handle_t knet_h, uint16_t host_id, const char *name)
 {
        int savederrno = 0, err = 0;
+       struct knet_host *host;
 
        if (!knet_h) {
                errno = EINVAL;
@@ -217,6 +218,14 @@ int knet_host_set_name(knet_handle_t knet_h, uint16_t host_id, const char *name)
        }
 
        if (!knet_h->host_index[host_id]) {
+               err = -1;
+               savederrno = EINVAL;
+               log_err(knet_h, KNET_SUB_HOST, "Unable to find host %u to set name: %s",
+                       host_id, strerror(savederrno));
+               goto exit_unlock;
+       }
+
+       if (!name) {
                err = -1;
                savederrno = EINVAL;
                log_err(knet_h, KNET_SUB_HOST, "Unable to set name for host %u: %s",
@@ -224,6 +233,16 @@ int knet_host_set_name(knet_handle_t knet_h, uint16_t host_id, const char *name)
                goto exit_unlock;
        }
 
+       for (host = knet_h->host_head; host != NULL; host = host->next) {
+               if (!strncmp(host->name, name, KNET_MAX_HOST_LEN - 1)) {
+                       err = -1;
+                       savederrno = EEXIST;
+                       log_err(knet_h, KNET_SUB_HOST, "Duplicated name found on host_id %u",
+                               host->host_id);
+                       goto exit_unlock;
+               }
+       }
+
        snprintf(knet_h->host_index[host_id]->name, KNET_MAX_HOST_LEN - 1, "%s", name);
 
 exit_unlock:
index 4d9d66987cf1d72510cac5fb0cfff8d0f91be723..f12f08610c33f4f56c499899f0b09146cb84cc24 100644 (file)
@@ -635,6 +635,7 @@ int knet_host_remove(knet_handle_t knet_h, uint16_t host_id);
  * name     - this name will be used for pretty logging and eventually
  *            search for hosts (see also get_name and get_id below).
  *            Only up to KNET_MAX_HOST_LEN - 1 bytes will be copied.
+ *            name has to be unique for each host.
  *
  * knet_host_set_name returns:
  *