OSDN Git Service

Read the correct amount of attributes
authorScott Bauer <sbauer@plzdonthack.me>
Fri, 7 Apr 2017 00:35:40 +0000 (18:35 -0600)
committerJakub Pawlowski <jpawlowski@google.com>
Thu, 28 Sep 2017 18:24:24 +0000 (18:24 +0000)
commit4d1470eb54592f7c9317419a2f1f83dc75cce770
tree63a95850740763f7b58fbadd53ce80994a560802
parent1ee8850324013cdb068963af615e9c525157b971
Read the correct amount of attributes

bta_gattc_cache_load currently attempts to read 0xFF attributes into an
allocation sized to num_attr attributes, which can be smaller than 0xFF.

There aren't more than num_attr bytes in correct data, but this breaks
with dynamic buffer overflow checking in CopperheadOS for the read
system call since fread ends up calling read, which obtains the size of
the allocation from the malloc implementation and then aborts due to the
(potential) overflow.

This would also fail with the default enabled _FORTIFY_SOURCE=2 feature
in the Android Open Source Project if osi_malloc was marked with the
alloc_size attribute. The way it wraps malloc loses that information so
fortify checks aren't done for calls like this.

Bug: 37160362
Change-Id: I68bd170d5378c9d9d21cbda376083bc0b857e15c
Signed-off-by: Scott Bauer <sbauer@plzdonthack.me>
[migrated to C++ file, added 0xFFFF limit and wrote commit message]
Signed-off-by: Daniel Micay <danielmicay@gmail.com>
bta/gatt/bta_gattc_cache.c