Skip to content

Commit 826fec9

Browse files
Adam Lesinskiandroid-build-team Robot
authored andcommitted
Check for null-terminator in ResStringPool::string8At
All other stringAt methods check for null termination. Be consistent so that upper levels don't end up with huge corrupt strings. Bug: 62537081 Test: none Change-Id: I17bdfb0c1e34507b66c6cad651bbdb12c5d4c417 (cherry picked from commit 3d35a0e) (cherry picked from commit 97f8cb01149b35b1832c7f9efe85ff19edf1083e) (cherry picked from commit 5ec65ae)
1 parent b0690cb commit 826fec9

1 file changed

Lines changed: 7 additions & 1 deletion

File tree

libs/androidfw/ResourceTypes.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -813,7 +813,13 @@ const char* ResStringPool::string8At(size_t idx, size_t* outLen) const
813813
*outLen = encLen;
814814

815815
if ((uint32_t)(str+encLen-strings) < mStringPoolSize) {
816-
return (const char*)str;
816+
// Reject malformed (non null-terminated) strings
817+
if (str[encLen] != 0x00) {
818+
ALOGW("Bad string block: string #%d is not null-terminated",
819+
(int)idx);
820+
return NULL;
821+
}
822+
return (const char*)str;
817823
} else {
818824
ALOGW("Bad string block: string #%d extends to %d, past end at %d\n",
819825
(int)idx, (int)(str+encLen-strings), (int)mStringPoolSize);

0 commit comments

Comments
 (0)