[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Bug in f_cntl()



This may be old-hat by now, but there's a bug in f_cntl() for 
file locking in FreeMint-1.12.4. Someone's put F_GETOPENS just
after the locking code, which expects to drop through to the
default case, but instead executes the F_GETOPENS code! I can't
provide a decent diff from this machine just yet, so here are
the code fragments:

Original dosfile.c:

		.
		.

		return 0;
	case FSTAT:
		return (*f->fc.fs->getxattr)(&f->fc, (XATTR *)arg);
	case F_SETLK:
	case F_SETLKW:
	/* make sure that the file was opened with appropriate permissions */
		fl = (struct flock *)arg;
		if (fl->l_type == F_RDLCK) {
			if ( (f->flags & O_RWMODE) == O_WRONLY )
				return EACCDN;
		} else {
			if ( (f->flags & O_RWMODE) == O_RDONLY )
				return EACCDN;
		}
		/* fall through to device ioctl */
	case F_GETOPENS:
		return get_opens (&f->fc, (struct listopens *)arg);
	default:
		TRACE(("Fcntl mode %x: calling ioctl",cmd));
		if (is_terminal(f)) {

		.
		.


And here's what it should look like...

		.
		.

		return 0;
	case FSTAT:
		return (*f->fc.fs->getxattr)(&f->fc, (XATTR *)arg);
	case F_GETOPENS:
		return get_opens (&f->fc, (struct listopens *)arg);
	case F_SETLK:
	case F_SETLKW:
	/* make sure that the file was opened with appropriate permissions */
		fl = (struct flock *)arg;
		if (fl->l_type == F_RDLCK) {
			if ( (f->flags & O_RWMODE) == O_WRONLY )
				return EACCDN;
		} else {
			if ( (f->flags & O_RWMODE) == O_RDONLY )
				return EACCDN;
		}
		/* fall through to device ioctl */
	default:
		TRACE(("Fcntl mode %x: calling ioctl",cmd));
		if (is_terminal(f)) {

		.
		.

Surely this has already been spotted?
Cheers, Steve