]> git.ipfire.org Git - thirdparty/asterisk.git/commitdiff
res_crypto.c: Avoid using the non-portable ALLPERMS macro.
authorSean Bright <sean@seanbright.com>
Mon, 5 Jun 2023 22:17:47 +0000 (18:17 -0400)
committerasterisk-org-access-app[bot] <120671045+asterisk-org-access-app[bot]@users.noreply.github.com>
Mon, 12 Jun 2023 14:22:52 +0000 (14:22 +0000)
ALLPERMS is not POSIX and it's trivial enough to not jump through
autoconf hoops to check for it.

Fixes #149.

res/res_crypto.c

index 2f7868cb625c9e92bc1fdfb38f94f96f3eb767ec..838e3a3de323010c4240ace7fadc993aef7699ae 100644 (file)
@@ -217,10 +217,15 @@ static struct ast_key *try_load_key(const char *dir, const char *fname, int ifd,
                return NULL;
        }
 
+       /* FILE_MODE_BITS is a bitwise OR of all possible file mode bits encoded in
+        * the `st_mode` member of `struct stat`. For POSIX compatible systems this
+        * will be 07777. */
+#define FILE_MODE_BITS (S_ISUID|S_ISGID|S_ISVTX|S_IRWXU|S_IRWXG|S_IRWXO)
+
        /* only user read or read/write modes allowed */
        if (ktype == AST_KEY_PRIVATE &&
-           ((st.st_mode & ALLPERMS) & ~(S_IRUSR | S_IWUSR)) != 0) {
-               ast_log(LOG_ERROR, "Private key file has bad permissions: %s: %#4o\n", ffname, st.st_mode & ALLPERMS);
+           ((st.st_mode & FILE_MODE_BITS) & ~(S_IRUSR | S_IWUSR)) != 0) {
+               ast_log(LOG_ERROR, "Private key file has bad permissions: %s: %#4o\n", ffname, st.st_mode & FILE_MODE_BITS);
                fclose(f);
                return NULL;
        }