]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
lxc_user_nic changes
authorSerge Hallyn <serge.hallyn@ubuntu.com>
Tue, 17 Dec 2013 16:34:25 +0000 (10:34 -0600)
committerSerge Hallyn <serge.hallyn@ubuntu.com>
Tue, 17 Dec 2013 16:34:25 +0000 (10:34 -0600)
1. catch a case if allowed number of nics is 0 (as opposed to no entry),
which previously would have allowed the user to sneak in one entry.

2. return false, not true, if something went heywire with creating the
/sys/class/net/$nic path to open.

Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
src/lxc/lxc_user_nic.c

index ac7a242c97ac751508e6c5c2e8cf66e0b6ec8aa5..16f1495c326af4e815706cce97d6e02dbc4bb2c5 100644 (file)
@@ -189,7 +189,7 @@ static bool nic_exists(char *nic)
 
        ret = snprintf(path, MAXPATHLEN, "/sys/class/net/%s", nic);
        if (ret < 0 || ret >= MAXPATHLEN) // should never happen!
-               return true;
+               return false;
        ret = stat(path, &sb);
        if (ret != 0)
                return false;
@@ -379,6 +379,9 @@ static bool get_nic_if_avail(int fd, char *me, int pid, char *intype, char *br,
 
        cull_entries(fd, me, intype, br);
 
+       if (allowed == 0)
+               return false;
+
        fstat(fd, &sb);
        len = sb.st_size;
        if (len != 0) {
@@ -393,7 +396,6 @@ static bool get_nic_if_avail(int fd, char *me, int pid, char *intype, char *br,
                        return false;
        }
 
-
        get_new_nicname(nicname, br, pid, cnic);
        /* me  ' ' intype ' ' br ' ' *nicname + '\n' + '\0' */
        slen = strlen(me) + strlen(intype) + strlen(br) + strlen(*nicname) + 5;