9fans - fans of the OS Plan 9 from Bell Labs
 help / color / mirror / Atom feed
* [9fans] DEL code in file name
@ 2013-03-09 13:38 arisawa
  2013-03-09 14:12 ` erik quanstrom
  0 siblings, 1 reply; 3+ messages in thread
From: arisawa @ 2013-03-09 13:38 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

Hello,

DEL code is allowed in file name?

I find the following code in cwfs/sub.c.

/*
 * what are legal characters in a name?
 * only disallow control characters.
 * a) utf avoids control characters.
 * b) '/' may not be the separator
 */
int
checkname(char *n)
{
	int i, c;

	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 Ename;
	}
	return Etoolong;
}

I have believed DEL code is one of control code
and should not be allowed in file name.
so I experimented.

maia% cat a.c
#include <u.h>
#include <libc.h>

void
usage(void)
{
	fprint(2,"usage: 8.out [-n] ....\n");
	exits("usage");
}


void
main(int argc, char *argv[])
{	int fd;
	ARGBEGIN{
	default: usage();
	}ARGEND

	//fd = create("a\xffb",OWRITE,0664);// accepted
	//fd = create("",OWRITE,0664);// rejected
	fd = create("\xff",OWRITE,0664);// accepted
	//fd = create("\x07",OWRITE,0664);// rejected
	if(fd < 0)
		sysfatal("not open %r");
	write(fd,"abc",3);
	close(fd);
}

# cwfs64x
term% ls -l
--rw-rw-r-- M 20 arisawa arisawa     3 Mar  9 21:39 ''
--rwxrwxr-x M 20 arisawa arisawa 36671 Mar  9 21:39 8.out
--rw-rw-r-- M 20 arisawa arisawa     3 Mar  2 22:13 a
--rw-rw-r-- M 20 arisawa arisawa  1858 Mar  9 21:39 a.8
--rw-r--r-- M 20 arisawa arisawa   602 Mar  9 21:39 a.c
--rw-rw-r-- M 20 arisawa arisawa  2526 Mar  6 20:59 dirty.txt
--rw-r--r-- M 20 arisawa arisawa   303 Mar  2 22:10 mkfile

# fossil
ar% ls -l
--rwxrwxr-x M 769572 arisawa arisawa 37602 Mar  9 22:18 8.out
--rw-rw-r-- M 769572 arisawa arisawa  1882 Mar  9 22:18 a.8
--rw-r--r-- M 769572 arisawa arisawa  1509 Mar  9 22:18 a.c
--rw-rw-r-- M 769572 arisawa arisawa     3 Mar  9 22:18 a
--rw-rw-r-- M 769572 arisawa arisawa  2526 Mar  6 20:59 dirty.txt
--rw-r--r-- M 769572 arisawa arisawa   303 Mar  2 22:10 mkfile
--rw-rw-r-- M 769572 arisawa arisawa     3 Mar  9 22:16

the result on cwfs64 and fossil are same. DEL code is accepted in file name.
"\xff" appears as zero length name,
"a\xffb" appears as like "a"
both files cannot be removed by rm command.





^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [9fans] DEL code in file name
  2013-03-09 13:38 [9fans] DEL code in file name arisawa
@ 2013-03-09 14:12 ` erik quanstrom
  2013-03-09 23:41   ` arisawa
  0 siblings, 1 reply; 3+ messages in thread
From: erik quanstrom @ 2013-03-09 14:12 UTC (permalink / raw)
  To: 9fans

i would think that a more complete solution
would be something like this.  (not tested)
0xff isn't delete, and isn't valid utf.  0x7f is
valid utf, but also not useful in a file name.

- erik

int
checkname(char *s)
{
	int i, n;
	Rune c;

	if(s == nil || *s == 0)
		return Ename;
	if(*s == '.' && (s[1] == 0 || (s[1] == '.' && s[2] == 0)))
		return Edot;
	for(i = 0;; i += n) {
		n = chartorune(&r, s);
		if(i+n >= NAMELEN)
			return Etoolong;
		if(r == 0)
			return 0;
		if(n == 1 && r == Runeerror)
			return Ename;
		if(r <= 040 || r == 0x7f)
			return Ename;
	}
}



^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [9fans] DEL code in file name
  2013-03-09 14:12 ` erik quanstrom
@ 2013-03-09 23:41   ` arisawa
  0 siblings, 0 replies; 3+ messages in thread
From: arisawa @ 2013-03-09 23:41 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

thanks erik,

some careless misses.

int
checkname(char *s)
{
	int i, n;
-	Rune c;
+	Rune r;

	if(s == nil || *s == 0)
		return Ename;
	if(*s == '.' && (s[1] == 0 || (s[1] == '.' && s[2] == 0)))
		return Edot;
	for(i = 0;; i += n) {
-		n = chartorune(&r, s);
+		n = chartorune(&r, &s[i]);
		if(i+n >= NAMELEN)
			return Etoolong;
		if(r == 0)
			return 0;
		if(n == 1 && r == Runeerror)
			return Ename;
-		if(r <= 040 || r == 0x7f)
+		if(r < 040 || r == 0x7f)
			return Ename;
	}
}




^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2013-03-09 23:41 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-03-09 13:38 [9fans] DEL code in file name arisawa
2013-03-09 14:12 ` erik quanstrom
2013-03-09 23:41   ` arisawa

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).