aboutsummaryrefslogtreecommitdiff
path: root/toys/android
diff options
context:
space:
mode:
authorElliott Hughes <enh@google.com>2017-05-23 17:35:49 -0700
committerRob Landley <rob@landley.net>2017-05-24 19:56:58 -0500
commit12f0744f340746b3a1c1accfdf993d6548f33e56 (patch)
tree7fa4ac6625bcaff12c300f4ef54d53649cfe7628 /toys/android
parent5a159cceb35fe08e444bd5a1771f8059888b03ff (diff)
downloadtoybox-12f0744f340746b3a1c1accfdf993d6548f33e56.tar.gz
Add and use xmmap.
Everyone forgets that mmap returns MAP_FAILED rather than NULL on failure. Every use of mmap in toybox was either doing the wrong check, or no check at all (including the two I personally added).
Diffstat (limited to 'toys/android')
-rw-r--r--toys/android/load_policy.c6
1 files changed, 3 insertions, 3 deletions
diff --git a/toys/android/load_policy.c b/toys/android/load_policy.c
index d9ff1486..bc0d5640 100644
--- a/toys/android/load_policy.c
+++ b/toys/android/load_policy.c
@@ -21,11 +21,11 @@ void load_policy_main(void)
{
int fd = xopenro(*toys.optargs);
off_t policy_len = fdlength(fd);
- char *policy_data = mmap(0, policy_len, PROT_READ, MAP_PRIVATE, fd, 0);
+ char *policy_data = xmmap(0, policy_len, PROT_READ, MAP_PRIVATE, fd, 0);
close(fd);
- if (!policy_data || security_load_policy(policy_data, policy_len) < 0)
- perror_exit("Couldn't %s %s", policy_data ? "load" : "read", *toys.optargs);
+ if (security_load_policy(policy_data, policy_len) < 0)
+ perror_exit("security_load_policy %s", *toys.optargs);
munmap(policy_data, policy_len);
}