@@ -62,7 +62,7 @@ use std::ffi::{OsStr, OsString};
6262use std:: fmt:: { self , Display } ;
6363use std:: fs;
6464use std:: io:: { self , BufRead , BufReader , Read , Write } ;
65- use std:: path:: { Path , PathBuf } ;
65+ use std:: path:: { Component , Path , PathBuf } ;
6666use std:: process:: { Child , Command , Stdio } ;
6767use std:: sync:: { Arc , Mutex } ;
6868use std:: thread:: { self , JoinHandle } ;
@@ -139,6 +139,8 @@ enum ErrorKind {
139139 ToolExecError ,
140140 /// Error occurred due to missing external tools.
141141 ToolNotFound ,
142+ /// One of the function arguments failed validation.
143+ InvalidArgument ,
142144}
143145
144146/// Represents an internal error that occurred, with an explanation.
@@ -943,6 +945,17 @@ impl Build {
943945 ///
944946 /// This will return a result instead of panicing; see compile() for the complete description.
945947 pub fn try_compile ( & self , output : & str ) -> Result < ( ) , Error > {
948+ let mut output_components = Path :: new ( output) . components ( ) ;
949+ match ( output_components. next ( ) , output_components. next ( ) ) {
950+ ( Some ( Component :: Normal ( _) ) , None ) => { }
951+ _ => {
952+ return Err ( Error :: new (
953+ ErrorKind :: InvalidArgument ,
954+ "argument of `compile` must be a single normal path component" ,
955+ ) ) ;
956+ }
957+ }
958+
946959 let ( lib_name, gnu_lib_name) = if output. starts_with ( "lib" ) && output. ends_with ( ".a" ) {
947960 ( & output[ 3 ..output. len ( ) - 2 ] , output. to_owned ( ) )
948961 } else {
0 commit comments