From cb6176cffb96e728c31b1bea082908a188be00ad Mon Sep 17 00:00:00 2001
From: Kristian Lein-Mathisen
Date: Sun, 29 Apr 2018 12:57:44 +0200
Subject: [PATCH 4/4] Check -L and -I for valid
In csc, you can pass -L and -I which will get passed on to
the C compiler with the -L prefix, like this:
csc -L/tmp/lib
This is handy. However, -L and -I are overloaded to pass options to
the C compiler that do not include the prefix, like this:
csc -L -lpng
In the first example, the compiler sees "-L/tmp/lib" and in the
seconds it sees only "-lpng". This causes problems if second version
is accidentally quoted, like this:
csc "-L -lpng"
Now C compiler will see "-L -lpng" which isn't an error but it should
be. We rarely have library directories that are called " -lpng". This
patch addresses that. If you actually have a library path that starts
with space, you will have to do something like `csc "-L./ madness"`.
---
csc.scm | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/csc.scm b/csc.scm
index 8b68b8fb..0fd3ea8e 100644
--- a/csc.scm
+++ b/csc.scm
@@ -773,8 +773,12 @@ EOF
[(and (> (string-length arg) 1)
(char=? #\- (string-ref arg 0)) )
(cond [(char=? #\L (string-ref arg 1))
+ (when (char-whitespace? (string-ref arg 2))
+ (error "bad -L argument, starts with whitespace" arg))
(set! link-options (append link-options (list arg))) ]
[(char=? #\I (string-ref arg 1))
+ (when (char-whitespace? (string-ref arg 2))
+ (error "bad -I argument: starts with whitespace" arg))
(set! compile-options (append compile-options (list arg))) ]
[(char=? #\D (string-ref arg 1))
(t-options "-feature" (substring arg 2)) ]
--
2.17.0