]> git.proxmox.com Git - mirror_iproute2.git/blobdiff - ip/ipvrf.c
Merge branch 'iproute2-master' into iproute2-next
[mirror_iproute2.git] / ip / ipvrf.c
index 0094cf8557cd7627846e075875db68427867b381..8a6b7f977b1423da8c1ee0df8379d90ba4716cc0 100644 (file)
@@ -74,7 +74,7 @@ static int vrf_identify(pid_t pid, char *name, size_t len)
                        if (end)
                                *end = '\0';
 
-                       strncpy(name, vrf, len - 1);
+                       strlcpy(name, vrf, len);
                        break;
                }
        }
@@ -336,8 +336,7 @@ static int vrf_path(char *vpath, size_t len)
                if (vrf)
                        *vrf = '\0';
 
-               strncpy(vpath, start, len - 1);
-               vpath[len - 1] = '\0';
+               strlcpy(vpath, start, len);
 
                /* if vrf path is just / then return nothing */
                if (!strcmp(vpath, "/"))
@@ -372,12 +371,12 @@ static int vrf_switch(const char *name)
 
        /* -1 on length to add '/' to the end */
        if (ipvrf_get_netns(netns, sizeof(netns) - 1) < 0)
-               return -1;
+               goto out;
 
        if (vrf_path(vpath, sizeof(vpath)) < 0) {
                fprintf(stderr, "Failed to get base cgroup path: %s\n",
                        strerror(errno));
-               return -1;
+               goto out;
        }
 
        /* if path already ends in netns then don't add it again */
@@ -428,13 +427,16 @@ static int vrf_switch(const char *name)
        snprintf(pid, sizeof(pid), "%d", getpid());
        if (write(fd, pid, strlen(pid)) < 0) {
                fprintf(stderr, "Failed to join cgroup\n");
-               goto out;
+               goto out2;
        }
 
        rc = 0;
+out2:
+       close(fd);
 out:
        free(mnt);
-       close(fd);
+
+       drop_cap();
 
        return rc;
 }