]> git.lizzy.rs Git - plan9front.git/blobdiff - sys/src/9/port/netif.c
devproc: make sure /proc/n/wait waits for the right process children
[plan9front.git] / sys / src / 9 / port / netif.c
index 3260a65b2024dc5de75b8c12d5def63159a41e76..e775fe847b65b0689f76f957e8ecb35aee87da0a 100644 (file)
@@ -18,8 +18,9 @@ static int parseaddr(uchar*, char*, int);
 void
 netifinit(Netif *nif, char *name, int nfile, ulong limit)
 {
-       strncpy(nif->name, name, KNAMELEN-1);
-       nif->name[KNAMELEN-1] = 0;
+       if(strlen(name) >= sizeof nif->name)
+               panic("netifinit: name too long: %s", name);
+       strcpy(nif->name, name);
        nif->nfile = nfile;
        nif->f = xalloc(nfile*sizeof(Netfile*));
        if (nif->f == nil)
@@ -66,7 +67,7 @@ netifgen(Chan *c, char*, Dirtab *vp, int, int i, Dir *dp)
 
        /* second level contains clone plus all the conversations */
        t = NETTYPE(c->qid.path);
-       if(t == N2ndqid || t == Ncloneqid || t == Naddrqid){
+       if(t == N2ndqid || t == Ncloneqid || t == Naddrqid || t == Nstatqid || t == Nifstatqid){
                switch(i) {
                case DEVDOTDOT:
                        q.type = QTDIR;
@@ -212,7 +213,7 @@ netifread(Netif *nif, Chan *c, void *a, long n, ulong offset)
        case Nctlqid:
                return readnum(offset, a, n, NETID(c->qid.path), NUMSIZE);
        case Nstatqid:
-               p = malloc(READSTR);
+               p = smalloc(READSTR);
                j = snprint(p, READSTR, "in: %llud\n", nif->inpackets);
                j += snprint(p+j, READSTR-j, "link: %d\n", nif->link);
                j += snprint(p+j, READSTR-j, "out: %llud\n", nif->outpackets);
@@ -232,7 +233,7 @@ netifread(Netif *nif, Chan *c, void *a, long n, ulong offset)
                free(p);
                return n;
        case Naddrqid:
-               p = malloc(READSTR);
+               p = smalloc(READSTR);
                j = 0;
                for(i = 0; i < nif->alen; i++)
                        j += snprint(p+j, READSTR-j, "%2.2ux", nif->addr[i]);
@@ -374,8 +375,10 @@ netifwstat(Netif *nif, Chan *c, uchar *db, int n)
                free(dir);
                error(Eshortstat);
        }
-       if(!emptystr(dir[0].uid))
-               strncpy(f->owner, dir[0].uid, KNAMELEN);
+       if(!emptystr(dir[0].uid)){
+               strncpy(f->owner, dir[0].uid, KNAMELEN-1);
+               f->owner[KNAMELEN-1] = 0;
+       }
        if(dir[0].mode != ~0UL)
                f->mode = dir[0].mode;
        free(dir);
@@ -471,7 +474,8 @@ netown(Netfile *p, char *o, int omode)
                        return -1;
                }
        }
-       strncpy(p->owner, o, KNAMELEN);
+       strncpy(p->owner, o, KNAMELEN-1);
+       p->owner[KNAMELEN-1] = 0;
        p->mode = 0660;
        unlock(&netlock);
        return 0;