void validstat(uint8_t *s, usize n) { usize m; char buf[64]; if(statcheck(s, n) < 0) error(Ebadstat); /* verify that name entry is acceptable */ s += STATFIXLEN - 4*BIT16SZ; /* location of first string */ /* * s now points at count for first string. * if it's too long, let the server decide; this is * only for his protection anyway. otherwise * we'd have to allocate and waserror. */ m = GBIT16(s); s += BIT16SZ; if(m+1 > sizeof buf) return; memmove(buf, s, m); buf[m] = '\0'; /* name could be '/' */ if(strcmp(buf, "/") != 0) validname(buf, 0); }
static int dirpackage(uint8_t *buf, int ts, Dir **d, uint32_t *nd, int dotu) { char *s; int ss, i, n, nn; uint m; *d = nil; *nd = 0; if(ts <= 0) return 0; /* * first find number of all stats, check they look like stats, & size all associated strings */ ss = 0; n = 0; for(i = 0; i < ts; i += m){ m = BIT16SZ + GBIT16(&buf[i]); if(statcheck(&buf[i], m, dotu) < 0) break; ss += m; n++; } if(i != ts) { DEBUG("statcheck"); return EBADRPC; } *d = malloc_9p(n * sizeof(Dir) + ss); if (*d == NULL) return ENOMEM; /* * then convert all buffers */ s = (char*)*d + n * sizeof(Dir); nn = 0; for(i = 0; i < ts; i += m){ m = BIT16SZ + GBIT16(&buf[i]); if(nn >= n || convM2D(&buf[i], m, *d + nn, s, dotu) != m){ free_9p(*d); *d = nil; DEBUG("convM2D"); return EBADRPC; } nn++; s += m; } *nd = nn; return 0; }
static void rstat(Fcall* f) { Dir d; cleannames(); convM2D(f->stat, f->nstat, &d, statbuf); d.name = importname(d.name); f->nstat = convD2M(&d, (uchar*)dirbuf, sizeof(dirbuf)); f->stat = (uchar*)dirbuf; if (statcheck(f->stat, f->nstat) < 0) dprint("stat fails\n"); }
static void twstat(Fcall* f) { Dir d; cleannames(); if (convM2D(f->stat, f->nstat, &d, statbuf) <= BIT16SZ) return; d.name = exportname(d.name); f->nstat = convD2M(&d, (uchar*)dirbuf, sizeof(dirbuf)); f->stat = (uchar*)dirbuf; if (statcheck(f->stat, f->nstat) < 0) dprint("stat fails\n"); }
static long dirpackage(uchar *buf, long ts, Dir **d) { char *s; long ss, i, n, nn, m; *d = nil; if(ts <= 0) return 0; /* * first find number of all stats, check they look like stats, & size all associated strings */ ss = 0; n = 0; for(i = 0; i < ts; i += m){ m = BIT16SZ + GBIT16(&buf[i]); if(statcheck(&buf[i], m) < 0) break; ss += m; n++; } if(i != ts) return -1; *d = malloc(n * sizeof(Dir) + ss); if(*d == nil) return -1; /* * then convert all buffers */ s = (char*)*d + n * sizeof(Dir); nn = 0; for(i = 0; i < ts; i += m){ m = BIT16SZ + GBIT16((uchar*)&buf[i]); if(nn >= n || convM2D(&buf[i], m, *d + nn, s) != m){ free(*d); *d = nil; return -1; } nn++; s += m; } return nn; }