forked frompostgres/postgres
- Notifications
You must be signed in to change notification settings - Fork6
Commit3652de3
committed
contrib/earthdistance: Use SQL-standard function bodies.
The @extschema:name@ feature added by72a5b1f allows us tomake earthdistance's references to the cube extension fullysearch-path-secure, so long as all those references areresolved at extension installation time not runtime.To do that, we must convert earthdistance's SQL functions tothe new SQL-standard style; but we wanted to do that anyway.The functions can be updated in our customary style by runningCREATE OR REPLACE FUNCTION in an extension update script.However, there's still problems in the "CREATE DOMAIN earth"command: its references to cube functions could be capturedby hostile objects in earthdistance's installation schema,if that's not where the cube extension is. Worse, the referenceto the cube type itself as the domain's base could be captured,and that's not something we could fix after-the-fact in theupdate script.What I've done about that is to change the "CREATE DOMAIN earth"command in the base script earthdistance--1.1.sql. Ordinarily,changing a released extension script is forbidden; but I thinkit's okay here since the results of successful (non-trojaned)script execution will be identical to before.A good deal of care is still needed to make the extension's scriptsproof against search-path-based attacks. We have to make sure thatall the function and operator invocations have exact argument-typematches, to forestall attacks based on supplying a better match.Fortunately earthdistance isn't very big, so I've just gone throughit and inspected each call to be sure of that. The only actual codechanges needed were to spell all floating-point constants in the style'-1'::float8, rather than depending on runtime type conversions and/ornegations. (I'm not sure that the shortcuts previously used wereattackable, but removing run-time effort is a good thing anyway.)I believe that this fixes earthdistance enough that we couldmark it trusted and remove the warnings about it that wereadded by7eeb1d9; but I've not done that here.The primary reason for dealing with this now is that we'vereceived reports of pg_upgrade failing for databases that useearthdistance functions in contexts like generated columns.That's a consequence of2af07e2 having restricted the search_pathused while evaluating such expressions. The only way to fix thatis to make the earthdistance functions independent of run-timesearch_path. This patch is very much nicer than the alternative ofattaching "SET search_path" clauses to earthdistance's functions:it is more secure and doesn't create a run-time penalty. Therefore,I've chosen to back-patch this to v16 where @extschema:name@was added. It won't help unless users update to 16.7 and issue"ALTER EXTENSION earthdistance UPDATE" before upgrading to 17,but at least there's now a way to deal with the problem withoutmanual intervention in the dump/restore process.Tom Lane and Ronan DunklauDiscussion:https://postgr.es/m/3316564.aeNJFYEL58@aivenlaptopDiscussion:https://postgr.es/m/6a6439f1-8039-44e2-8fb9-59028f7f2014@mailbox.org1 parentad950ea commit3652de3
File tree
5 files changed
+81
-6
lines changed- contrib/earthdistance
5 files changed
+81
-6
lines changedLines changed: 2 additions & 1 deletion
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
3 | 3 |
| |
4 | 4 |
| |
5 | 5 |
| |
6 |
| - | |
| 6 | + | |
| 7 | + | |
7 | 8 |
| |
8 | 9 |
| |
9 | 10 |
| |
|
Lines changed: 73 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + |
Lines changed: 4 additions & 4 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
27 | 27 |
| |
28 | 28 |
| |
29 | 29 |
| |
30 |
| - | |
31 |
| - | |
32 |
| - | |
33 |
| - | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
34 | 34 |
| |
35 | 35 |
| |
36 | 36 |
| |
|
Lines changed: 1 addition & 1 deletion
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
1 | 1 |
| |
2 | 2 |
| |
3 |
| - | |
| 3 | + | |
4 | 4 |
| |
5 | 5 |
| |
6 | 6 |
|
Lines changed: 1 addition & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
20 | 20 |
| |
21 | 21 |
| |
22 | 22 |
| |
| 23 | + | |
23 | 24 |
| |
24 | 25 |
| |
25 | 26 |
| |
|
0 commit comments
Comments
(0)