@@ -62,7 +62,7 @@ use std::ffi::{OsStr, OsString};
62
62
use std:: fmt:: { self , Display } ;
63
63
use std:: fs;
64
64
use std:: io:: { self , BufRead , BufReader , Read , Write } ;
65
- use std:: path:: { Path , PathBuf } ;
65
+ use std:: path:: { Component , Path , PathBuf } ;
66
66
use std:: process:: { Child , Command , Stdio } ;
67
67
use std:: sync:: { Arc , Mutex } ;
68
68
use std:: thread:: { self , JoinHandle } ;
@@ -139,6 +139,8 @@ enum ErrorKind {
139
139
ToolExecError ,
140
140
/// Error occurred due to missing external tools.
141
141
ToolNotFound ,
142
+ /// One of the function arguments failed validation.
143
+ InvalidArgument ,
142
144
}
143
145
144
146
/// Represents an internal error that occurred, with an explanation.
@@ -943,6 +945,17 @@ impl Build {
943
945
///
944
946
/// This will return a result instead of panicing; see compile() for the complete description.
945
947
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
+
946
959
let ( lib_name, gnu_lib_name) = if output. starts_with ( "lib" ) && output. ends_with ( ".a" ) {
947
960
( & output[ 3 ..output. len ( ) - 2 ] , output. to_owned ( ) )
948
961
} else {
0 commit comments