From e0fd5d3c112df92b3d104b519ed09770f24d2ecf Mon Sep 17 00:00:00 2001
From: Ron Yorston <rmy@pobox.com>
Date: Tue, 24 Oct 2023 11:41:12 +0100
Subject: make: stricter checks for c:/path filenames

When checking target names or looking for a target rule be more
strict about the form of Windows paths allowed.

Alter the error message when neither a target rule or macro
assignment has been detected.

Adds 88-96 bytes.
---
 miscutils/make.c | 15 +++++++++------
 1 file changed, 9 insertions(+), 6 deletions(-)

diff --git a/miscutils/make.c b/miscutils/make.c
index 695f77fa6..22d6abeea 100644
--- a/miscutils/make.c
+++ b/miscutils/make.c
@@ -438,6 +438,13 @@ check_name(const char *name)
 {
 	const char *s;
 
+#if ENABLE_PLATFORM_MINGW32
+	if (!posix || (pragma & P_WINDOWS)) {
+		if (isalpha(name[0]) && name[1] == ':' && name[2] == '/') {
+			name += 3;
+		}
+	}
+#endif
 	if (!posix) {
 		for (s = name; *s; ++s) {
 			if (*s == '=')
@@ -447,10 +454,6 @@ check_name(const char *name)
 	}
 
 	for (s = name; *s; ++s) {
-#if ENABLE_PLATFORM_MINGW32
-		if ((pragma & P_WINDOWS) && *s == ':')
-			continue;
-#endif
 		if ((pragma & P_TARGET_NAME) || !POSIX_2017 ?
 				!(isfname(*s) || *s == '/') : !ispname(*s))
 			return FALSE;
@@ -1175,7 +1178,7 @@ find_colon(char *p)
 	for (q = p; (q = strchr(q, ':')); ++q) {
 		if (posix && !(pragma & P_WINDOWS))
 			break;
-		if (q[1] != '/')
+		if (q == p || !isalpha(q[-1]) || q[1] != '/')
 			break;
 	}
 	if (q != NULL) {
@@ -2123,7 +2126,7 @@ input(FILE *fd, int ilevel)
 			setmacro(a, q, level);
 			free(newq);
 		} else {
-			error("expected macro definition");
+			error("missing separator");
 		}
 
  end_loop:
-- 
cgit v1.2.3-55-g6feb