From a518a4f6023582744fa271ec279375dd3d51a4d4 Mon Sep 17 00:00:00 2001 From: Ron Yorston Date: Mon, 10 Jun 2024 12:46:50 +0100 Subject: make: limit changes to pragmas The special target .PRAGMA could be used to set or reset pragmas. Doing anything other than setting pragmas very early in execution is likely to be problematic. Limit the abilities of .PRAGMA: - Specifying .PRAGMA with no prerequisites now does nothing: pragmas are not reset. - The posix_2017 and posix_202x pragmas can only be used to change the enforced POSIX level from the default. Any further attempt to change POSIX level results in a warning. Adds 16-32 bytes. --- miscutils/make.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/miscutils/make.c b/miscutils/make.c index 7d2196139..c9f8cc506 100644 --- a/miscutils/make.c +++ b/miscutils/make.c @@ -656,7 +656,10 @@ set_pragma(const char *name) if (idx >= BIT_POSIX_2017) { // POSIX level is stored in a separate variable. // No bits in 'pragma' are used. - posix_level = idx - BIT_POSIX_2017; + if (posix_level == DEFAULT_POSIX_LEVEL) + posix_level = idx - BIT_POSIX_2017; + else if (posix_level != idx - BIT_POSIX_2017) + warning("unable to change POSIX level"); } else { pragma |= 1 << idx; } @@ -693,10 +696,6 @@ addrule(struct name *np, struct depend *dp, struct cmd *cp, int flag) if ((np->n_flag & N_SPECIAL) && !dp && !cp) { if (strcmp(np->n_name, ".PHONY") == 0) return; -#if ENABLE_FEATURE_MAKE_POSIX - if (strcmp(np->n_name, ".PRAGMA") == 0) - pragma = 0; -#endif freerules(np->n_rule); np->n_rule = NULL; return; -- cgit v1.2.3-55-g6feb