From 12f0744f340746b3a1c1accfdf993d6548f33e56 Mon Sep 17 00:00:00 2001 From: Elliott Hughes Date: Tue, 23 May 2017 17:35:49 -0700 Subject: 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). --- toys/android/load_policy.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'toys/android') 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); } -- cgit v1.2.3