Skip to content

Commit cab299f

Browse files
committed
Prevent users from passing code containing to play.rust-lang.org and inform them about the error
1 parent 6b05581 commit cab299f

File tree

1 file changed

+8
-10
lines changed

1 file changed

+8
-10
lines changed

src/playground.rs

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -257,17 +257,15 @@ pub fn eval(args: Args) -> Result<(), Error> {
257257
.get("code")
258258
.ok_or("Unable to retrieve param: query")?;
259259

260-
let code = format!(
261-
"fn main(){{
262-
println!(\"{{:?}}\",{{
263-
{}
264-
}});
265-
}}",
266-
code
267-
);
260+
if code.contains("fn main") {
261+
api::send_reply(&args, "code passed to ?eval should not contain `fn main`")?;
262+
} else {
263+
let code = format!("fn main(){{ println!(\"{{:?}}\",{{ {} }}); }}", code);
264+
265+
let result = run_code(&args, &code)?;
266+
api::send_reply(&args, &result)?;
267+
}
268268

269-
let result = run_code(&args, &code)?;
270-
api::send_reply(&args, &result)?;
271269
Ok(())
272270
}
273271

0 commit comments

Comments
 (0)