`umask(mode)` calls that do not verify `(mode & 0777) == mode` are
rejected when the libc FORTIFY checks are enabled [1].
The unrestricted `~perms` was indeed making this assertion fail.
[1]: https://android.googlesource.com/platform/bionic/+/refs/tags/android-11.0.0_r3/libc/bionic/fortify.cpp#404
FILE *fopenmask(const char *filename, const char *mode, mode_t perms) {
mode_t mask = umask(0);
perms &= ~mask;
- umask(~perms);
+ umask(~perms & 0777);
FILE *f = fopen(filename, mode);
if(!f) {