gralloc1: Check input parameters for null addresses

Check input parameters for null addresses for few interface
methods.

Change-Id: If5ec3cf8edde5c97730e0a64e0f38536245ff29b
CRs-Fixed: 2114346
diff --git a/libgralloc1/gr_device_impl.cpp b/libgralloc1/gr_device_impl.cpp
index d421ff1..c900d23 100644
--- a/libgralloc1/gr_device_impl.cpp
+++ b/libgralloc1/gr_device_impl.cpp
@@ -65,7 +65,7 @@
 
 int gralloc_device_open(const struct hw_module_t *module, const char *name, hw_device_t **device) {
   int status = -EINVAL;
-  if (!strcmp(name, GRALLOC_HARDWARE_MODULE_ID)) {
+  if (module && device && !strcmp(name, GRALLOC_HARDWARE_MODULE_ID)) {
     gralloc1::GrallocImpl * /*gralloc1_device_t*/ dev = gralloc1::GrallocImpl::GetInstance(module);
     *device = reinterpret_cast<hw_device_t *>(dev);
     if (dev) {
@@ -105,7 +105,7 @@
 
 void GrallocImpl::GetCapabilities(struct gralloc1_device *device, uint32_t *out_count,
                                   int32_t  /*gralloc1_capability_t*/ *out_capabilities) {
-  if (device != nullptr) {
+  if (device != nullptr && out_count != nullptr) {
     if (out_capabilities != nullptr && *out_count >= 3) {
       out_capabilities[0] = GRALLOC1_CAPABILITY_TEST_ALLOCATE;
       out_capabilities[1] = GRALLOC1_CAPABILITY_LAYERED_BUFFERS;
@@ -178,7 +178,7 @@
 
 gralloc1_error_t GrallocImpl::Dump(gralloc1_device_t *device, uint32_t *out_size,
                                    char *out_buffer) {
-  if (!device) {
+  if (!device || !out_size) {
     ALOGE("Gralloc Error : device=%p", (void *)device);
     return GRALLOC1_ERROR_BAD_DESCRIPTOR;
   }
@@ -213,7 +213,7 @@
 
 gralloc1_error_t GrallocImpl::CreateBufferDescriptor(gralloc1_device_t *device,
                                                      gralloc1_buffer_descriptor_t *out_descriptor) {
-  if (!device) {
+  if (!device || !out_descriptor) {
     return GRALLOC1_ERROR_BAD_DESCRIPTOR;
   }
   GrallocImpl const *dev = GRALLOC_IMPL(device);