ff801c63ced60346e56845ceb7adfdd8f14738b4
[feed/telephony.git] / net / asterisk / patches / 180-res_crypto.c-Avoid-using-the-non-portable-ALLPERMS-m.patch
1 From 94c884d5b8afca96164852cfb29fc496bc5b9e0a Mon Sep 17 00:00:00 2001
2 From: Sean Bright <sean@seanbright.com>
3 Date: Mon, 5 Jun 2023 18:17:47 -0400
4 Subject: [PATCH] res_crypto.c: Avoid using the non-portable ALLPERMS macro.
5
6 ALLPERMS is not POSIX and it's trivial enough to not jump through
7 autoconf hoops to check for it.
8
9 Fixes #149.
10 ---
11 res/res_crypto.c | 9 +++++++--
12 1 file changed, 7 insertions(+), 2 deletions(-)
13
14 --- a/res/res_crypto.c
15 +++ b/res/res_crypto.c
16 @@ -217,10 +217,15 @@ static struct ast_key *try_load_key(cons
17 return NULL;
18 }
19
20 + /* PERM_MASK is a bitwise OR of all possible file mode bits encoded in the
21 + * `st_mode` member of `struct stat`. For POSIX compatible systems this
22 + * will be 07777. */
23 +#define PERM_MASK (S_ISUID|S_ISGID|S_ISVTX|S_IRWXU|S_IRWXG|S_IRWXO)
24 +
25 /* only user read or read/write modes allowed */
26 if (ktype == AST_KEY_PRIVATE &&
27 - ((st.st_mode & ALLPERMS) & ~(S_IRUSR | S_IWUSR)) != 0) {
28 - ast_log(LOG_ERROR, "Private key file has bad permissions: %s: %#4o\n", ffname, st.st_mode & ALLPERMS);
29 + ((st.st_mode & PERM_MASK) & ~(S_IRUSR | S_IWUSR)) != 0) {
30 + ast_log(LOG_ERROR, "Private key file has bad permissions: %s: %#4o\n", ffname, st.st_mode & PERM_MASK);
31 fclose(f);
32 return NULL;
33 }