diff options
author | Colin Cross <ccross@android.com> | 2013-11-08 19:07:38 -0800 |
---|---|---|
committer | Ubuntu <vishal.bhoj@linaro.org> | 2014-06-05 10:01:58 +0000 |
commit | 252c3d98c82a327ba2d0132d24dddb89e671000f (patch) | |
tree | 544a9630ed49c262398d860ff8e54391f5091cb9 | |
parent | 5ed738af7aad5411bec1445dee4d72880fd1a320 (diff) |
libion: add NULL checks
Check for NULL in any library function that takes a pointer.
Change-Id: I9ae8887b5ae0f231583173ee6a9dfd2f8c4611ec
(cherry picked from commit 9919436a5f7d01bd3ea090888fb3712c7bf0d5f4)
-rw-r--r-- | libion/ion.c | 23 |
1 files changed, 20 insertions, 3 deletions
diff --git a/libion/ion.c b/libion/ion.c index ea40245f..98509492 100644 --- a/libion/ion.c +++ b/libion/ion.c @@ -65,6 +65,9 @@ int ion_alloc(int fd, size_t len, size_t align, unsigned int heap_mask, .flags = flags, }; + if (handle == NULL) + return -EINVAL; + ret = ion_ioctl(fd, ION_IOC_ALLOC, &data); if (ret < 0) return ret; @@ -83,11 +86,17 @@ int ion_free(int fd, ion_user_handle_t handle) int ion_map(int fd, ion_user_handle_t handle, size_t length, int prot, int flags, off_t offset, unsigned char **ptr, int *map_fd) { + int ret; struct ion_fd_data data = { .handle = handle, }; - int ret = ion_ioctl(fd, ION_IOC_MAP, &data); + if (map_fd == NULL) + return -EINVAL; + if (ptr == NULL) + return -EINVAL; + + ret = ion_ioctl(fd, ION_IOC_MAP, &data); if (ret < 0) return ret; *map_fd = data.fd; @@ -106,11 +115,15 @@ int ion_map(int fd, ion_user_handle_t handle, size_t length, int prot, int ion_share(int fd, ion_user_handle_t handle, int *share_fd) { int map_fd; + int ret; struct ion_fd_data data = { .handle = handle, }; - int ret = ion_ioctl(fd, ION_IOC_SHARE, &data); + if (share_fd == NULL) + return -EINVAL; + + ret = ion_ioctl(fd, ION_IOC_SHARE, &data); if (ret < 0) return ret; *share_fd = data.fd; @@ -136,11 +149,15 @@ int ion_alloc_fd(int fd, size_t len, size_t align, unsigned int heap_mask, int ion_import(int fd, int share_fd, ion_user_handle_t *handle) { + int ret; struct ion_fd_data data = { .fd = share_fd, }; - int ret = ion_ioctl(fd, ION_IOC_IMPORT, &data); + if (handle == NULL) + return -EINVAL; + + ret = ion_ioctl(fd, ION_IOC_IMPORT, &data); if (ret < 0) return ret; *handle = data.handle; |