Skip to content

Commit 9a753ec

Browse files
committed
First version with a working recursion limit
Until now it has been possible to trigger a stack overflow by passing crafted inputs (e.g. a string of 1000 `(`). This is problematic when using the library to parse user input. This commit adds a recursion limit so long as the library is compiled with `std`. The limit ensures that malicious inputs cannot trigger a stack overflow, by preventing excessively deep recursion. Since the SQL parser is so big, I've added this protection to every `Parser` method that returns a `Result`. The actual recursive patterns in the AST are more limited, but with such a large parser it's much harder to identify them and put targeted protections in place.
1 parent 12a3e97 commit 9a753ec

File tree

3 files changed

+291
-1
lines changed

3 files changed

+291
-1
lines changed

Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ path = "src/lib.rs"
2020

2121
[features]
2222
default = ["std"]
23-
std = []
23+
std = ["scopeguard"]
2424
# Enable JSON output in the `cli` example:
2525
json_example = ["serde_json", "serde"]
2626

@@ -32,6 +32,7 @@ serde = { version = "1.0", features = ["derive"], optional = true }
3232
# of dev-dependencies because of
3333
# https://github.com/rust-lang/cargo/issues/1596
3434
serde_json = { version = "1.0", optional = true }
35+
scopeguard = { version = "1.1.0", optional = true }
3536

3637
[dev-dependencies]
3738
simple_logger = "2.1"

0 commit comments

Comments
 (0)