Commit 9082118693 for asterisk.org
commit 90821186935271ebe1257df35585807f2fb74284
Author: Hector Cao <hector.cao@canonical.com>
Date: Fri Sep 4 16:14:12 2026 +0200
utils: fix SWAP64_32 macro precedence bug on big-endian
The SWAP64_32 macro did not parenthesize its argument. When a combined
flag mask such as (AST_OPT_FLAG_EXEC | AST_OPT_FLAG_NO_COLOR) was passed,
the '<<' shift bound tighter than the '|', so the wrong bits were set.
On big-endian systems (e.g. s390x) this caused ast_set_flag64() and a
later single-flag ast_test_flag64() to disagree, so 'asterisk -rx <cmd>'
dropped into the interactive console instead of executing the command.
Parenthesize the macro argument so the whole expression is evaluated
before the word swap. Little-endian was unaffected.
diff --git a/include/asterisk/utils.h b/include/asterisk/utils.h
index b34fce167c..f03a1ef483 100644
--- a/include/asterisk/utils.h
+++ b/include/asterisk/utils.h
@@ -128,7 +128,7 @@ extern unsigned int __unsigned_int_flags_dummy;
* \retval The flags with the upper and lower 32 bits swapped if the system is big-endian,
*/
#if defined(BYTE_ORDER) && (BYTE_ORDER == BIG_ENDIAN)
-#define SWAP64_32(flags) (((uint64_t)flags << 32) | ((uint64_t)flags >> 32))
+#define SWAP64_32(flags) (((uint64_t)(flags) << 32) | ((uint64_t)(flags) >> 32))
#elif defined(BYTE_ORDER) && (BYTE_ORDER == LITTLE_ENDIAN)
#define SWAP64_32(flags) (flags)
#else
diff --git a/utils/extconf.c b/utils/extconf.c
index 5585ace416..f2750b7e4f 100644
--- a/utils/extconf.c
+++ b/utils/extconf.c
@@ -675,7 +675,7 @@ struct ast_flags { /* stolen from utils.h */
unsigned int flags;
};
#if __BYTE_ORDER == __BIG_ENDIAN
-#define SWAP64_32(flags) (((uint64_t)flags << 32) | ((uint64_t)flags >> 32))
+#define SWAP64_32(flags) (((uint64_t)(flags) << 32) | ((uint64_t)(flags) >> 32))
#else
#define SWAP64_32(flags) (flags)
#endif