Skip to content

Commit 3407429

Browse files
authored
Fix panic in Statement.iterate() on invalid bind parameters (#224)
2 parents 290fae6 + fd52e9a commit 3407429

3 files changed

Lines changed: 21 additions & 1 deletion

File tree

‎integration-tests/tests/async.test.js‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,16 @@ test.serial("Statement.iterate()", async (t) => {
139139
}
140140
});
141141

142+
test.serial("Statement.iterate() with invalid bind parameter", async (t) => {
143+
const db = t.context.db;
144+
145+
const stmt = await db.prepare("SELECT * FROM users WHERE id = ?");
146+
const error = await t.throwsAsync(async () => {
147+
await stmt.iterate([[1, 2, 3]]);
148+
});
149+
t.is(error.message, "SQLite3 can only bind numbers, strings, bigints, buffers, and null");
150+
});
151+
142152
test.serial("Statement.all()", async (t) => {
143153
const db = t.context.db;
144154

‎integration-tests/tests/sync.test.js‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,16 @@ test.serial("Statement.iterate()", async (t) => {
159159
}
160160
});
161161

162+
test.serial("Statement.iterate() with invalid bind parameter", async (t) => {
163+
const db = t.context.db;
164+
165+
const stmt = db.prepare("SELECT * FROM users WHERE id = ?");
166+
const error = t.throws(() => {
167+
stmt.iterate([[1, 2, 3]]);
168+
});
169+
t.is(error.message, "SQLite3 can only bind numbers, strings, bigints, buffers, and null");
170+
});
171+
162172
test.serial("Statement.all()", async (t) => {
163173
const db = t.context.db;
164174

‎src/lib.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1082,7 +1082,7 @@ impl Statement {
10821082
let pluck = self.mode.pluck.load(Ordering::SeqCst);
10831083
let stmt = self.stmt.clone();
10841084
stmt.reset();
1085-
let params = map_params(&stmt, params).unwrap();
1085+
let params = map_params(&stmt, params)?;
10861086
let stmt_for_query = self.stmt.clone();
10871087
let stmt_for_iter = stmt_for_query.clone();
10881088
let query_timeout = self.resolve_query_timeout(query_options);

0 commit comments

Comments
 (0)