From: Colin Cross Date: Tue, 25 Jun 2013 01:42:21 +0000 (-0700) Subject: bionic: use the size of the file to determine property area size X-Git-Tag: android-x86-4.4-r1~19^2~54^2^2~1 X-Git-Url: http://git.osdn.net/view?a=commitdiff_plain;h=1ec20a086cb1da1d7455a36ea5d2ea4856426ea0;p=android-x86%2Fbionic.git bionic: use the size of the file to determine property area size On the reader size, don't assume that the property size is PA_SIZE, read it from the size of the file. Allows init to use a different property size without recompiling statically linked executables. (cherry picked from commit 285b42a04cbe8e627a75c9bfb3c7cb3f7b539267) Change-Id: I074204e9e6591b35faf7c1c58fb11ec162aff7bf --- diff --git a/libc/bionic/system_properties.c b/libc/bionic/system_properties.c index 481e6ae45..0d421956e 100644 --- a/libc/bionic/system_properties.c +++ b/libc/bionic/system_properties.c @@ -112,7 +112,8 @@ static char property_filename[PATH_MAX] = PROP_FILENAME; prop_area *__system_property_area__ = NULL; -const size_t PA_DATA_SIZE = PA_SIZE - sizeof(prop_area); +size_t pa_data_size; +size_t pa_size; static int get_fd_from_env(void) { @@ -153,11 +154,14 @@ static int map_prop_area_rw() if (ftruncate(fd, PA_SIZE) < 0) goto out; - pa = mmap(NULL, PA_SIZE, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); + pa_size = PA_SIZE; + pa_data_size = pa_size - sizeof(prop_area); + + pa = mmap(NULL, pa_size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); if(pa == MAP_FAILED) goto out; - memset(pa, 0, PA_SIZE); + memset(pa, 0, pa_size); pa->magic = PROP_AREA_MAGIC; pa->version = PROP_AREA_VERSION; /* reserve root node */ @@ -230,18 +234,20 @@ static int map_prop_area() if ((fd_stat.st_uid != 0) || (fd_stat.st_gid != 0) || ((fd_stat.st_mode & (S_IWGRP | S_IWOTH)) != 0) - || (fd_stat.st_size < PA_SIZE) ) { + || (fd_stat.st_size < sizeof(prop_area)) ) { goto cleanup; } - prop_area *pa = mmap(NULL, PA_SIZE, PROT_READ, MAP_SHARED, fd, 0); + pa_size = fd_stat.st_size; + pa_data_size = pa_size - sizeof(prop_area); + prop_area *pa = mmap(NULL, pa_size, PROT_READ, MAP_SHARED, fd, 0); if (pa == MAP_FAILED) { goto cleanup; } if((pa->magic != PROP_AREA_MAGIC) || (pa->version != PROP_AREA_VERSION)) { - munmap(pa, PA_SIZE); + munmap(pa, pa_size); goto cleanup; } @@ -267,7 +273,7 @@ static void *new_prop_obj(size_t size, prop_off_t *off) prop_area *pa = __system_property_area__; size = ALIGN(size, sizeof(uint32_t)); - if (pa->bytes_used + size > PA_DATA_SIZE) + if (pa->bytes_used + size > pa_data_size) return NULL; *off = pa->bytes_used; @@ -310,7 +316,7 @@ static prop_info *new_prop_info(const char *name, uint8_t namelen, static void *to_prop_obj(prop_off_t off) { - if (off > PA_DATA_SIZE) + if (off > pa_data_size) return NULL; return __system_property_area__->data + off;