diff options
author | Ron Yorston <rmy@pobox.com> | 2024-06-04 13:55:25 +0100 |
---|---|---|
committer | Ron Yorston <rmy@pobox.com> | 2024-06-04 13:55:25 +0100 |
commit | 48f5ecaf27d900ffea77dbda762202d73223ec32 (patch) | |
tree | 9d34878731b1ef7cd60ef09ad16f22976e7125a2 | |
parent | ac688749879e4867bee0be6a07eec21a65cec585 (diff) | |
download | busybox-w32-48f5ecaf27d900ffea77dbda762202d73223ec32.tar.gz busybox-w32-48f5ecaf27d900ffea77dbda762202d73223ec32.tar.bz2 busybox-w32-48f5ecaf27d900ffea77dbda762202d73223ec32.zip |
make: explicitly verify order of arguments
POSIX requires macro assignments to precede targets on the command
line. This requirement has been relaxed as a non-POSIX extension.
Verify the constraint has been applied in POSIX mode. This ensures
that the command:
make --posix target A=1
fails before it tries to update the target.
It also catches the case where POSIX mode had not been set with the
--posix option or PDPMAKE_POSIXLY_CORRECT environment but was then
set by the .POSIX special target in the makefile. In this case the
command line was scanned for macro assignments without enforcing
POSIX mode while targets were processed with POSIX mode enabled.
Adds 96 bytes.
-rw-r--r-- | miscutils/make.c | 23 |
1 files changed, 16 insertions, 7 deletions
diff --git a/miscutils/make.c b/miscutils/make.c index f44de5df6..0235d9877 100644 --- a/miscutils/make.c +++ b/miscutils/make.c | |||
@@ -3156,16 +3156,25 @@ int make_main(int argc UNUSED_PARAM, char **argv) | |||
3156 | if (!POSIX_2017) | 3156 | if (!POSIX_2017) |
3157 | mark_special(".PHONY", OPT_phony, N_PHONY); | 3157 | mark_special(".PHONY", OPT_phony, N_PHONY); |
3158 | 3158 | ||
3159 | if (posix) { | ||
3160 | // In POSIX mode only targets should now be in argv. | ||
3161 | found_target = FALSE; | ||
3162 | for (char **a = argv; *a; a++) { | ||
3163 | if (!strchr(*a, '=')) | ||
3164 | found_target = TRUE; | ||
3165 | else if (found_target) | ||
3166 | error("macro assignments must precede targets"); | ||
3167 | } | ||
3168 | } | ||
3169 | |||
3159 | estat = 0; | 3170 | estat = 0; |
3160 | found_target = FALSE; | 3171 | found_target = FALSE; |
3161 | for (; *argv; argv++) { | 3172 | for (; *argv; argv++) { |
3162 | // In POSIX mode only targets should now be in argv. | 3173 | // Skip macro assignments. |
3163 | // As an extension macros may still be present: skip them. | 3174 | if (strchr(*argv, '=')) |
3164 | if (posix || !strchr(*argv, '=')) | 3175 | continue; |
3165 | { | 3176 | found_target = TRUE; |
3166 | found_target = TRUE; | 3177 | estat |= make(newname(*argv), 0); |
3167 | estat |= make(newname(*argv), 0); | ||
3168 | } | ||
3169 | } | 3178 | } |
3170 | if (!found_target) { | 3179 | if (!found_target) { |
3171 | if (!firstname) | 3180 | if (!firstname) |