@@ -1880,88 +1880,92 @@ static int range_read(struct policydb *p, void *fp)
1880
1880
return rc ;
1881
1881
}
1882
1882
1883
- static int filename_trans_read (struct policydb * p , void * fp )
1883
+ static int filename_trans_read_one (struct policydb * p , void * fp )
1884
1884
{
1885
1885
struct filename_trans * ft ;
1886
- struct filename_trans_datum * otype ;
1887
- char * name ;
1888
- u32 nel , len ;
1886
+ struct filename_trans_datum * otype = NULL ;
1887
+ char * name = NULL ;
1888
+ u32 len ;
1889
1889
__le32 buf [4 ];
1890
- int rc , i ;
1890
+ int rc ;
1891
1891
1892
- if (p -> policyvers < POLICYDB_VERSION_FILENAME_TRANS )
1893
- return 0 ;
1892
+ ft = kzalloc (sizeof (* ft ), GFP_KERNEL );
1893
+ if (!ft )
1894
+ return - ENOMEM ;
1895
+
1896
+ rc = - ENOMEM ;
1897
+ otype = kmalloc (sizeof (* otype ), GFP_KERNEL );
1898
+ if (!otype )
1899
+ goto out ;
1894
1900
1901
+ /* length of the path component string */
1895
1902
rc = next_entry (buf , fp , sizeof (u32 ));
1896
1903
if (rc )
1897
- return rc ;
1898
- nel = le32_to_cpu (buf [0 ]);
1899
-
1900
- for (i = 0 ; i < nel ; i ++ ) {
1901
- otype = NULL ;
1902
- name = NULL ;
1903
-
1904
- rc = - ENOMEM ;
1905
- ft = kzalloc (sizeof (* ft ), GFP_KERNEL );
1906
- if (!ft )
1907
- goto out ;
1908
-
1909
- rc = - ENOMEM ;
1910
- otype = kmalloc (sizeof (* otype ), GFP_KERNEL );
1911
- if (!otype )
1912
- goto out ;
1913
-
1914
- /* length of the path component string */
1915
- rc = next_entry (buf , fp , sizeof (u32 ));
1916
- if (rc )
1917
- goto out ;
1918
- len = le32_to_cpu (buf [0 ]);
1904
+ goto out ;
1905
+ len = le32_to_cpu (buf [0 ]);
1919
1906
1920
- /* path component string */
1921
- rc = str_read (& name , GFP_KERNEL , fp , len );
1922
- if (rc )
1923
- goto out ;
1907
+ /* path component string */
1908
+ rc = str_read (& name , GFP_KERNEL , fp , len );
1909
+ if (rc )
1910
+ goto out ;
1924
1911
1925
- ft -> name = name ;
1912
+ ft -> name = name ;
1926
1913
1927
- rc = next_entry (buf , fp , sizeof (u32 ) * 4 );
1928
- if (rc )
1929
- goto out ;
1914
+ rc = next_entry (buf , fp , sizeof (u32 ) * 4 );
1915
+ if (rc )
1916
+ goto out ;
1930
1917
1931
- ft -> stype = le32_to_cpu (buf [0 ]);
1932
- ft -> ttype = le32_to_cpu (buf [1 ]);
1933
- ft -> tclass = le32_to_cpu (buf [2 ]);
1918
+ ft -> stype = le32_to_cpu (buf [0 ]);
1919
+ ft -> ttype = le32_to_cpu (buf [1 ]);
1920
+ ft -> tclass = le32_to_cpu (buf [2 ]);
1934
1921
1935
- otype -> otype = le32_to_cpu (buf [3 ]);
1922
+ otype -> otype = le32_to_cpu (buf [3 ]);
1936
1923
1937
- rc = ebitmap_set_bit (& p -> filename_trans_ttypes , ft -> ttype , 1 );
1938
- if (rc )
1939
- goto out ;
1924
+ rc = ebitmap_set_bit (& p -> filename_trans_ttypes , ft -> ttype , 1 );
1925
+ if (rc )
1926
+ goto out ;
1940
1927
1941
- rc = hashtab_insert (p -> filename_trans , ft , otype );
1942
- if (rc ) {
1943
- /*
1944
- * Do not return -EEXIST to the caller, or the system
1945
- * will not boot.
1946
- */
1947
- if (rc != - EEXIST )
1948
- goto out ;
1949
- /* But free memory to avoid memory leak. */
1950
- kfree (ft );
1951
- kfree (name );
1952
- kfree (otype );
1953
- }
1928
+ rc = hashtab_insert (p -> filename_trans , ft , otype );
1929
+ if (rc ) {
1930
+ /*
1931
+ * Do not return -EEXIST to the caller, or the system
1932
+ * will not boot.
1933
+ */
1934
+ if (rc == - EEXIST )
1935
+ rc = 0 ;
1936
+ goto out ;
1954
1937
}
1955
- hash_eval (p -> filename_trans , "filenametr" );
1956
1938
return 0 ;
1957
1939
out :
1958
1940
kfree (ft );
1959
1941
kfree (name );
1960
1942
kfree (otype );
1961
-
1962
1943
return rc ;
1963
1944
}
1964
1945
1946
+ static int filename_trans_read (struct policydb * p , void * fp )
1947
+ {
1948
+ u32 nel ;
1949
+ __le32 buf [1 ];
1950
+ int rc , i ;
1951
+
1952
+ if (p -> policyvers < POLICYDB_VERSION_FILENAME_TRANS )
1953
+ return 0 ;
1954
+
1955
+ rc = next_entry (buf , fp , sizeof (u32 ));
1956
+ if (rc )
1957
+ return rc ;
1958
+ nel = le32_to_cpu (buf [0 ]);
1959
+
1960
+ for (i = 0 ; i < nel ; i ++ ) {
1961
+ rc = filename_trans_read_one (p , fp );
1962
+ if (rc )
1963
+ return rc ;
1964
+ }
1965
+ hash_eval (p -> filename_trans , "filenametr" );
1966
+ return 0 ;
1967
+ }
1968
+
1965
1969
static int genfs_read (struct policydb * p , void * fp )
1966
1970
{
1967
1971
int i , j , rc ;
0 commit comments