@@ -1065,26 +1065,39 @@ int ocfs2_find_entry(const char *name, int namelen,
10651065{
10661066	struct  buffer_head  * bh ;
10671067	struct  ocfs2_dir_entry  * res_dir  =  NULL ;
1068+ 	int  ret  =  0 ;
10681069
10691070	if  (ocfs2_dir_indexed (dir ))
10701071		return  ocfs2_find_entry_dx (name , namelen , dir , lookup );
10711072
1073+ 	if  (unlikely (i_size_read (dir ) <= 0 )) {
1074+ 		ret  =  - EFSCORRUPTED ;
1075+ 		mlog_errno (ret );
1076+ 		goto out ;
1077+ 	}
10721078	/* 
10731079	 * The unindexed dir code only uses part of the lookup 
10741080	 * structure, so there's no reason to push it down further 
10751081	 * than this. 
10761082	 */ 
1077- 	if  (OCFS2_I (dir )-> ip_dyn_features  &  OCFS2_INLINE_DATA_FL )
1083+ 	if  (OCFS2_I (dir )-> ip_dyn_features  &  OCFS2_INLINE_DATA_FL ) {
1084+ 		if  (unlikely (i_size_read (dir ) >  dir -> i_sb -> s_blocksize )) {
1085+ 			ret  =  - EFSCORRUPTED ;
1086+ 			mlog_errno (ret );
1087+ 			goto out ;
1088+ 		}
10781089		bh  =  ocfs2_find_entry_id (name , namelen , dir , & res_dir );
1079- 	else 
1090+ 	}  else  { 
10801091		bh  =  ocfs2_find_entry_el (name , namelen , dir , & res_dir );
1092+ 	}
10811093
10821094	if  (bh  ==  NULL )
10831095		return  - ENOENT ;
10841096
10851097	lookup -> dl_leaf_bh  =  bh ;
10861098	lookup -> dl_entry  =  res_dir ;
1087- 	return  0 ;
1099+ out :
1100+ 	return  ret ;
10881101}
10891102
10901103/* 
@@ -2009,6 +2022,7 @@ int ocfs2_lookup_ino_from_name(struct inode *dir, const char *name,
20092022 * 
20102023 * Return 0 if the name does not exist 
20112024 * Return -EEXIST if the directory contains the name 
2025+  * Return -EFSCORRUPTED if found corruption 
20122026 * 
20132027 * Callers should have i_rwsem + a cluster lock on dir 
20142028 */ 
@@ -2022,9 +2036,12 @@ int ocfs2_check_dir_for_entry(struct inode *dir,
20222036	trace_ocfs2_check_dir_for_entry (
20232037		(unsigned long long )OCFS2_I (dir )-> ip_blkno , namelen , name );
20242038
2025- 	if  (ocfs2_find_entry (name , namelen , dir , & lookup ) ==  0 ) {
2039+ 	ret  =  ocfs2_find_entry (name , namelen , dir , & lookup );
2040+ 	if  (ret  ==  0 ) {
20262041		ret  =  - EEXIST ;
20272042		mlog_errno (ret );
2043+ 	} else  if  (ret  ==  - ENOENT ) {
2044+ 		ret  =  0 ;
20282045	}
20292046
20302047	ocfs2_free_dir_lookup_result (& lookup );
0 commit comments