From 18fae75350bcd5f19ef90afb533e3fbedfd4c83b Mon Sep 17 00:00:00 2001 From: Colin Cross Date: Tue, 22 Jul 2014 15:55:08 -0700 Subject: [PATCH] crash if getNativeBuffer() called on NULL GraphicBuffer If getNativeBuffer() is called on a NULL GraphicBuffer the static_cast of this from GraphicBuffer* to ANativeWindowBuffer* will return a small pointer like (ANativeWindowBuffer*)0x10. This value can propagate past NULL checks until it causes a crash far away from the original NULL pointer. Crash immediately instead. Change-Id: Id614b9eb1484108b3c3c733545309844c4b87532 --- libs/ui/GraphicBuffer.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/libs/ui/GraphicBuffer.cpp b/libs/ui/GraphicBuffer.cpp index e21dc53ca..9b0bd601c 100644 --- a/libs/ui/GraphicBuffer.cpp +++ b/libs/ui/GraphicBuffer.cpp @@ -126,6 +126,7 @@ void GraphicBuffer::dumpAllocationsToSystemLog() ANativeWindowBuffer* GraphicBuffer::getNativeBuffer() const { + LOG_ALWAYS_FATAL_IF(this == NULL, "getNativeBuffer() called on NULL GraphicBuffer"); return static_cast( const_cast(this)); }