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)
/* 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;
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);
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]);
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);
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;