-
-
Notifications
You must be signed in to change notification settings - Fork 249
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Stop SpiClient soundness from regressing #1214
Merged
workingjubilee
merged 13 commits into
pgcentralfoundation:develop
from
workingjubilee:joy/add-trybuild-test
Jul 20, 2023
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
817c191
Stop SpiClient soundness from regressing
workingjubilee 897ef60
Set a bunch of flags randomly to test
workingjubilee 3adb638
set more
workingjubilee 34095cb
more
workingjubilee b05cdca
Bump SCCACHE_MAX_FRAME_LENGTH
workingjubilee b79dd96
Revert "Disable versioned_custom_libname_so"
workingjubilee 9e6c809
Revert "Disable hello_versioned_so test (#1192)"
workingjubilee fbe7bea
cleanup harder
workingjubilee a8844ca
Clean up midway
workingjubilee 2fdbb3e
Big money no whammies
workingjubilee d819f7e
Allow test capture again
workingjubilee c2d549c
Revert "cleanup harder"
workingjubilee d3c8340
Use an order-of-magnitude smaller example for cursor.rs
workingjubilee File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
use trybuild::TestCases; | ||
|
||
#[test] | ||
fn ui() { | ||
let t = TestCases::new(); | ||
t.compile_fail("tests/ui/*.rs"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
use pgrx::prelude::*; | ||
use std::error::Error; | ||
|
||
#[pg_test] | ||
fn issue1209() -> Result<Option<String>, Box<dyn Error>> { | ||
// create the cursor we actually care about | ||
let mut res = Spi::connect(|c| { | ||
c.open_cursor("select 'hello world' from generate_series(1, 1000)", None) | ||
.fetch(1000) | ||
.unwrap() | ||
}); | ||
|
||
// here we just perform some allocations to make sure that the previous cursor gets invalidated | ||
for _ in 0..100 { | ||
Spi::connect(|c| c.open_cursor("select 1", None).fetch(1).unwrap()); | ||
} | ||
|
||
// later elements are probably more likely to point to deallocated memory | ||
for _ in 0..100 { | ||
res.next(); | ||
} | ||
|
||
// segfault | ||
Ok(res.next().unwrap().get::<String>(1)?) | ||
} | ||
|
||
fn main() {} | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
error: lifetime may not live long enough | ||
--> tests/ui/escaping-spiclient-1209-cursor.rs:8:9 | ||
| | ||
7 | let mut res = Spi::connect(|c| { | ||
| -- return type of closure is SpiTupleTable<'2> | ||
| | | ||
| has type `SpiClient<'1>` | ||
8 | / c.open_cursor("select 'hello world' from generate_series(1, 1000)", None) | ||
9 | | .fetch(1000) | ||
10 | | .unwrap() | ||
| |_____________________^ returning this value requires that `'1` must outlive `'2` | ||
|
||
error[E0515]: cannot return value referencing temporary value | ||
--> tests/ui/escaping-spiclient-1209-cursor.rs:8:9 | ||
| | ||
8 | c.open_cursor("select 'hello world' from generate_series(1, 1000)", None) | ||
| ^------------------------------------------------------------------------ | ||
| | | ||
| _________temporary value created here | ||
| | | ||
9 | | .fetch(1000) | ||
10 | | .unwrap() | ||
| |_____________________^ returns a value referencing data owned by the current function | ||
| | ||
= help: use `.collect()` to allocate the iterator | ||
|
||
error: lifetime may not live long enough | ||
--> tests/ui/escaping-spiclient-1209-cursor.rs:15:26 | ||
| | ||
15 | Spi::connect(|c| c.open_cursor("select 1", None).fetch(1).unwrap()); | ||
| -- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ returning this value requires that `'1` must outlive `'2` | ||
| || | ||
| |return type of closure is SpiTupleTable<'2> | ||
| has type `SpiClient<'1>` | ||
|
||
error[E0515]: cannot return value referencing temporary value | ||
--> tests/ui/escaping-spiclient-1209-cursor.rs:15:26 | ||
| | ||
15 | Spi::connect(|c| c.open_cursor("select 1", None).fetch(1).unwrap()); | ||
| -------------------------------^^^^^^^^^^^^^^^^^^ | ||
| | | ||
| returns a value referencing data owned by the current function | ||
| temporary value created here | ||
| | ||
= help: use `.collect()` to allocate the iterator |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
use pgrx::prelude::*; | ||
use std::error::Error; | ||
|
||
#[pg_extern] | ||
fn issue1209_prepared_stmt(q: &str) -> Result<Option<String>, Box<dyn Error>> { | ||
use pgrx::spi::Query; | ||
|
||
let prepared = { Spi::connect(|c| c.prepare(q, None))? }; | ||
|
||
Ok(Spi::connect(|c| prepared.execute(&c, Some(1), None)?.first().get(1))?) | ||
} | ||
|
||
fn main() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
error: lifetime may not live long enough | ||
--> tests/ui/escaping-spiclient-1209-prep-stmt.rs:8:39 | ||
| | ||
8 | let prepared = { Spi::connect(|c| c.prepare(q, None))? }; | ||
| -- ^^^^^^^^^^^^^^^^^^ returning this value requires that `'1` must outlive `'2` | ||
| || | ||
| |return type of closure is std::result::Result<PreparedStatement<'2>, pgrx::spi::SpiError> | ||
| has type `SpiClient<'1>` |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't like the frivolous mains but whatever.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
might be able to avoid with
#![crate_type = "lib"]
? not sure.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tried, unfortunately didn't work.