Skip to content

Commit

Permalink
libcutils: abort for invalid fd
Browse files Browse the repository at this point in the history
If ashmem accessors are being called with a file descriptor that
belongs to anything other than ashmem, we need to stop it right
now so that they can fix the caller.

Bug: 26871259
Change-Id: Icf9aafc3631a80b9af6fe0fea03599d61e285d21
  • Loading branch information
Mark Salyzyn authored and Steve Kondik committed Jul 15, 2016
1 parent 70a8c7a commit 53bf234
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions libcutils/ashmem-dev.c
Original file line number Diff line number Diff line change
Expand Up @@ -118,15 +118,16 @@ static int __ashmem_is_ashmem(int fd)
}

if (rdev) {
ALOGE("illegal fd=%d mode=0%o rdev=%d:%d expected 0%o %d:%d",
LOG_ALWAYS_FATAL("illegal fd=%d mode=0%o rdev=%d:%d expected 0%o %d:%d",
fd, st.st_mode, major(st.st_rdev), minor(st.st_rdev),
S_IFCHR | S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IRGRP,
major(rdev), minor(rdev));
} else {
ALOGE("illegal fd=%d mode=0%o rdev=%d:%d expected 0%o",
LOG_ALWAYS_FATAL("illegal fd=%d mode=0%o rdev=%d:%d expected 0%o",
fd, st.st_mode, major(st.st_rdev), minor(st.st_rdev),
S_IFCHR | S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IRGRP);
}
/* NOTREACHED */

errno = ENOTTY;
return -1;
Expand Down

0 comments on commit 53bf234

Please sign in to comment.