[Toybox] [PATCH] Fix load_policy error reporting.
enh
enh at google.com
Tue Apr 7 13:18:58 PDT 2015
submitted to AOSP as
https://android-review.googlesource.com/#/c/145712/ (SHA
f697e055e906e35908cac0a356d986e466765de6).
On Sat, Mar 28, 2015 at 1:16 PM, enh <enh at google.com> wrote:
> Fix load_policy error reporting.
>
> Also switch to xopen for O_CLOEXEC paranoia and to avoid a conditional.
>
> diff --git a/toys/android/load_policy.c b/toys/android/load_policy.c
> index aa59f36..8496736 100644
> --- a/toys/android/load_policy.c
> +++ b/toys/android/load_policy.c
> @@ -20,18 +20,13 @@ config LOAD_POLICY
> void load_policy_main(void)
> {
> char *path = *toys.optargs;
> - char *policy_data = 0;
> - off_t policy_len;
> - int fd;
> -
> - if ((fd = open(path, O_RDONLY)) != -1) {
> - policy_len = fdlength(fd);
> - policy_data = mmap(0, policy_len, PROT_READ, MAP_PRIVATE, fd, 0);
> - close(fd);
> - }
> + int fd = xopen(path, O_RDONLY);
> + off_t policy_len = fdlength(fd);
> + char *policy_data = mmap(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: %s", policy_data ? "load" : "read", path);
> + perror_exit("Couldn't %s %s", policy_data ? "load" : "read", path);
>
> munmap(policy_data, policy_len);
> }
--
Elliott Hughes - http://who/enh - http://jessies.org/~enh/
Android native code/tools questions? Mail me/drop by/add me as a reviewer.
More information about the Toybox
mailing list