cwfs: simplify checkname, allow space character

front
cinap_lenrek 2011-12-12 12:16:35 +01:00
parent 733dab56a1
commit dab4f2afc7
3 changed files with 18 additions and 46 deletions

View File

@ -659,15 +659,8 @@ f_create(Chan *cp, Fcall *in, Fcall *ou)
goto out;
}
accessdir(p, d, FREAD, f->uid);
if(!strncmp(in->name, ".", sizeof(in->name)) ||
!strncmp(in->name, "..", sizeof(in->name))) {
ou->err = Edot;
if(ou->err = checkname(in->name))
goto out;
}
if(checkname(in->name)) {
ou->err = Ename;
goto out;
}
addr1 = 0;
slot1 = 0; /* set */
for(addr=0;; addr++) {
@ -1393,8 +1386,11 @@ f_wstat(Chan *cp, Fcall *in, Fcall *ou)
* must have write permission in parent
*/
if (strncmp(d->name, xd.name, sizeof(d->name)) != 0) {
if (checkname(xd.name) || !d1 ||
strcmp(xd.name, ".") == 0 || strcmp(xd.name, "..") == 0) {
if(ou->err = checkname(xd.name))
goto out;
/* rename root? */
if(!d1){
ou->err = Ename;
goto out;
}

View File

@ -110,29 +110,6 @@ mkdir9p2(Dir* dir, Dentry* dentry, void* strs)
return p-op;
}
static int
checkname9p2(char* name)
{
char *p;
/*
* Return error or 0 if OK.
*/
if(name == nil || *name == 0)
return Ename;
for(p = name; *p != 0; p++){
if(p-name >= NAMELEN-1)
return Etoolong;
if((*p & 0xFF) <= 040)
return Ename;
}
if(strcmp(name, ".") == 0 || strcmp(name, "..") == 0)
return Edot;
return 0;
}
static int
version(Chan* chan, Fcall* f, Fcall* r)
{
@ -825,7 +802,7 @@ fs_create(Chan* chan, Fcall* f, Fcall* r)
* Check the name is valid (and will fit in an old
* directory entry for the moment).
*/
if(error = checkname9p2(f->name))
if(error = checkname(f->name))
goto out;
addr1 = 0;
@ -1547,7 +1524,7 @@ fs_wstat(Chan* chan, Fcall* f, Fcall*, char* strs)
* Check .name is valid and different to the current.
*/
if(dir.name != nil && *dir.name != '\0'){
if(error = checkname9p2(dir.name))
if(error = checkname(dir.name))
goto out;
if(strncmp(dir.name, d->name, NAMELEN))
op = 1;

View File

@ -534,19 +534,18 @@ checkname(char *n)
{
int i, c;
for(i=0; i<NAMELEN; i++) {
c = *n & 0xff;
if(c == 0) {
if(i == 0)
return 1;
memset(n, 0, NAMELEN-i);
if(n == 0 || *n == 0)
return Ename;
if(*n == '.' && (n[1] == 0 || (n[1] == '.' && n[2] == 0)))
return Edot;
for(i=1; i<NAMELEN; i++) {
c = n[i] & 0xff;
if(c == 0)
return 0;
}
if(c <= 040)
return 1;
n++;
if(c < 040)
return Ename;
}
return 1; /* too long */
return Etoolong;
}
void