am b871e5d6
: Merge "system_properties: do more checking of file"
# Via Gerrit Code Review (1) and Nick Kralevich (1) * commit 'b871e5d6b3b4a214c7f19bdfca7663f1fe49fda8': system_properties: do more checking of file
This commit is contained in:
commit
27818d2a16
@ -69,6 +69,7 @@ static int get_fd_from_env(void)
|
|||||||
int __system_properties_init(void)
|
int __system_properties_init(void)
|
||||||
{
|
{
|
||||||
bool fromFile = true;
|
bool fromFile = true;
|
||||||
|
int result = -1;
|
||||||
|
|
||||||
if(__system_property_area__ != ((void*) &dummy_props)) {
|
if(__system_property_area__ != ((void*) &dummy_props)) {
|
||||||
return 0;
|
return 0;
|
||||||
@ -96,26 +97,35 @@ int __system_properties_init(void)
|
|||||||
|
|
||||||
struct stat fd_stat;
|
struct stat fd_stat;
|
||||||
if (fstat(fd, &fd_stat) < 0) {
|
if (fstat(fd, &fd_stat) < 0) {
|
||||||
return -1;
|
goto cleanup;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((fd_stat.st_uid != 0)
|
||||||
|
|| (fd_stat.st_gid != 0)
|
||||||
|
|| ((fd_stat.st_mode & (S_IWGRP | S_IWOTH)) != 0)) {
|
||||||
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
prop_area *pa = mmap(0, fd_stat.st_size, PROT_READ, MAP_SHARED, fd, 0);
|
prop_area *pa = mmap(0, fd_stat.st_size, PROT_READ, MAP_SHARED, fd, 0);
|
||||||
|
|
||||||
if (fromFile) {
|
|
||||||
close(fd);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (pa == MAP_FAILED) {
|
if (pa == MAP_FAILED) {
|
||||||
return -1;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
if((pa->magic != PROP_AREA_MAGIC) || (pa->version != PROP_AREA_VERSION)) {
|
if((pa->magic != PROP_AREA_MAGIC) || (pa->version != PROP_AREA_VERSION)) {
|
||||||
munmap(pa, fd_stat.st_size);
|
munmap(pa, fd_stat.st_size);
|
||||||
return -1;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
__system_property_area__ = pa;
|
__system_property_area__ = pa;
|
||||||
return 0;
|
result = 0;
|
||||||
|
|
||||||
|
cleanup:
|
||||||
|
if (fromFile) {
|
||||||
|
close(fd);
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
const prop_info *__system_property_find_nth(unsigned n)
|
const prop_info *__system_property_find_nth(unsigned n)
|
||||||
|
Loading…
Reference in New Issue
Block a user