FreeBSD/sbin/fsck_ffs/dir.c
/*
 * Verify that a directory entry is valid.
 * This is a superset of the checks made in the kernel.
 */
Verify that a directory entry is valid.
This is a superset of the checks made in the kernel.
Verify that a directory entry is valid . This is a superset of the checks made in the kernel .
static int
dircheck(struct inodesc *idesc, struct direct *dp)
{
	size_t size;
	char *cp;
	u_char type;
	u_int8_t namlen;
	int spaceleft;
	spaceleft = DIRBLKSIZ - (idesc->id_loc % DIRBLKSIZ);
	if (dp->d_reclen == 0 ||
	    dp->d_reclen > spaceleft ||
	    (dp->d_reclen & 0x3) != 0)
		goto bad;
	if (dp->d_ino == 0)
		return (1);
	size = DIRSIZ(0, dp);
	namlen = dp->d_namlen;
	type = dp->d_type;
	if (dp->d_reclen < size ||
	    idesc->id_filesize < size ||
	    namlen == 0 ||
	    type > 15)
		goto bad;
	for (cp = dp->d_name, size = 0; size < namlen; size++)
		if (*cp == '\0' || (*cp++ == '/'))
			goto bad;
	if (*cp != '\0')
		goto bad;
	return (1);
bad:
	if (debug)
		printf("Bad dir: ino %d reclen %d namlen %d type %d name %s\n",
		    dp->d_ino, dp->d_reclen, dp->d_namlen, dp->d_type,
		    dp->d_name);
	return (0);
}
static int dircheck ( struct inodesc * idesc , struct direct * dp ) { size_t size ; char * cp ; u_char type ; u_int8_t namlen ; int spaceleft ; spaceleft = DIRBLKSIZ - ( idesc -> id_loc % DIRBLKSIZ ) ; if ( dp -> d_reclen == 0 || dp -> d_reclen > spaceleft || ( dp -> d_reclen & 0x3 ) != 0 ) goto bad ; if ( dp -> d_ino == 0 ) return ( 1 ) ; size = DIRSIZ ( 0 , dp ) ; namlen = dp -> d_namlen ; type = dp -> d_type ; if ( dp -> d_reclen < size || idesc -> id_filesize < size || namlen == 0 || type > 15 ) goto bad ; for ( cp = dp -> d_name , size = 0 ; size < namlen ; size ++ ) if ( * cp == ' \0 ' || ( * cp ++ == ' ' ) ) goto bad ; if ( * cp != ' \0 ' ) goto bad ; return ( 1 ) ; bad : if ( debug ) printf ( " \n " , dp -> d_ino , dp -> d_reclen , dp -> d_namlen , dp -> d_type , dp -> d_name ) ; return ( 0 ) ; }
Verify that a directory entry is valid.
Verify that a directory entry is valid .