Buildroot Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [Buildroot] [RFC PATCH] toolchain-external: instrument wrapper to warn about unsafe paths
@ 2014-02-10 23:28 Thomas Petazzoni
  2014-02-11  0:33 ` Yann E. MORIN
  2014-02-11  6:21 ` Baruch Siach
  0 siblings, 2 replies; 6+ messages in thread
From: Thomas Petazzoni @ 2014-02-10 23:28 UTC (permalink / raw)
  To: buildroot

The CodeSourcery toolchains have a very interesting feature: they warn
the user when an unsafe header or library path is used, i.e a path
that will lead host headers or libraries to leak into the build.

This commit adds a similar functionality into our external toolchain
wrapper, so that it can be used with all external toolchains, and can
also be tuned as needed. By default, the external toolchain wrapper
now gives warnings such as:

  WARNING: unsafe header/library path used in cross-compilation: '-I /usr/foo'
  WARNING: unsafe header/library path used in cross-compilation: '-L /usr/bleh'

but the compilation continues successfully. One can then easily grep
in his build log to search for occurences of this message.

Optionally, if BR_PARANOID_WRAPPER is defined in the environment, the
external wrapper will instead error out and abort the compilation. We
could then one day imagine setting this BR_PARANOID_WRAPPER in the
autobuilders.

A similar change could be made to the internal toolchain backend
either by making it use a wrapper like the external toolchain one, or
by adding some patches to gcc, by borrowing the changes made by the
CodeSourcery people.

Signed-off-by: Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
---
 .../toolchain-external/ext-toolchain-wrapper.c     | 27 ++++++++++++++++++++++
 1 file changed, 27 insertions(+)

diff --git a/toolchain/toolchain-external/ext-toolchain-wrapper.c b/toolchain/toolchain-external/ext-toolchain-wrapper.c
index 81c6ed1..c8dcad5 100644
--- a/toolchain/toolchain-external/ext-toolchain-wrapper.c
+++ b/toolchain/toolchain-external/ext-toolchain-wrapper.c
@@ -77,6 +77,7 @@ int main(int argc, char **argv)
 	char *progpath = argv[0];
 	char *basename;
 	char *env_debug;
+	char *paranoid_wrapper;
 	int ret, i, count = 0, debug;
 
 	/* Calculate the relative paths */
@@ -178,6 +179,32 @@ int main(int argc, char **argv)
 	}
 #endif /* ARCH || TUNE || CPU */
 
+	paranoid_wrapper = getenv("BR_PARANOID_WRAPPER");
+
+	/* Check for unsafe library and header paths */
+	for (i = 1; i < argc; i++) {
+		if (!strncmp(argv[i], "-I/usr", strlen("-I/usr")) ||
+		    !strncmp(argv[i], "-L/usr", strlen("-L/usr"))) {
+			fprintf(stderr, "%s: unsafe header/library path used in cross-compilation: '%s'\n",
+				paranoid_wrapper ? "ERROR" : "WARNING", argv[i]);
+			if (paranoid_wrapper)
+				exit(1);
+			continue;
+		}
+
+		if (!strcmp(argv[i], "-L") || !strcmp(argv[i], "-I")) {
+			if (i == argc)
+				continue;
+			if (!strncmp(argv[i+1], "/usr", strlen("/usr"))) {
+				fprintf(stderr, "%s: unsafe header/library path used in cross-compilation: '%s %s'\n",
+					paranoid_wrapper ? "ERROR" : "WARNING", argv[i], argv[i + 1]);
+				if (paranoid_wrapper)
+					exit(1);
+				continue;
+			}
+		}
+	}
+
 	/* append forward args */
 	memcpy(cur, &argv[1], sizeof(char *) * (argc - 1));
 	cur += argc - 1;
-- 
1.8.3.2

^ permalink raw reply related	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2014-02-11 17:53 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-02-10 23:28 [Buildroot] [RFC PATCH] toolchain-external: instrument wrapper to warn about unsafe paths Thomas Petazzoni
2014-02-11  0:33 ` Yann E. MORIN
2014-02-11  8:18   ` Thomas Petazzoni
2014-02-11 17:53     ` Yann E. MORIN
2014-02-11  6:21 ` Baruch Siach
2014-02-11  8:24   ` Thomas Petazzoni

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox