Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 8a37951

Browse files
committed
Mark built-in coercion functions as leakproof where possible.
Making these leakproof seems helpful since (for example) if you have a function f(int8) that is leakproof, you don't want it to effectively become non-leakproof when you apply it to an int4 or int2 column. But that's what happens today, since the implicit up-coercion will not be leakproof. Most of the coercion functions that visibly can't throw errors are functions that convert numeric datatypes to other, wider ones. Notable is that float4_numeric and float8_numeric can be marked leakproof; before commit a57d312 they could not have been. I also marked the functions that coerce strings to "name" as leakproof; that's okay today because they truncate silently, but if we ever reconsidered that behavior then they could no longer be leakproof. I desisted from marking rtrim1() as leakproof; it appears so right now, but the code seems a little too complex and perhaps subject to change, since it's shared with other SQL functions. Discussion: https://postgr.es/m/459322.1595607431@sss.pgh.pa.us
1 parent 2a24942 commit 8a37951

File tree

3 files changed

+78
-52
lines changed

3 files changed

+78
-52
lines changed

src/include/catalog/catversion.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,6 @@
5353
*/
5454

5555
/* yyyymmddN */
56-
#define CATALOG_VERSION_NO 202007202
56+
#define CATALOG_VERSION_NO 202007251
5757

5858
#endif

src/include/catalog/pg_proc.dat

Lines changed: 52 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -698,11 +698,11 @@
698698
proname => 'dlog1', prorettype => 'float8', proargtypes => 'float8',
699699
prosrc => 'dlog1' },
700700
{ oid => '235', descr => 'convert int2 to float8',
701-
proname => 'float8', prorettype => 'float8', proargtypes => 'int2',
702-
prosrc => 'i2tod' },
701+
proname => 'float8', proleakproof => 't', prorettype => 'float8',
702+
proargtypes => 'int2', prosrc => 'i2tod' },
703703
{ oid => '236', descr => 'convert int2 to float4',
704-
proname => 'float4', prorettype => 'float4', proargtypes => 'int2',
705-
prosrc => 'i2tof' },
704+
proname => 'float4', proleakproof => 't', prorettype => 'float4',
705+
proargtypes => 'int2', prosrc => 'i2tof' },
706706
{ oid => '237', descr => 'convert float8 to int2',
707707
proname => 'int2', prorettype => 'int2', proargtypes => 'float8',
708708
prosrc => 'dtoi2' },
@@ -879,26 +879,26 @@
879879
proargtypes => 'float8 float8 float8 int4', prosrc => 'width_bucket_float8' },
880880

881881
{ oid => '311', descr => 'convert float4 to float8',
882-
proname => 'float8', prorettype => 'float8', proargtypes => 'float4',
883-
prosrc => 'ftod' },
882+
proname => 'float8', proleakproof => 't', prorettype => 'float8',
883+
proargtypes => 'float4', prosrc => 'ftod' },
884884
{ oid => '312', descr => 'convert float8 to float4',
885885
proname => 'float4', prorettype => 'float4', proargtypes => 'float8',
886886
prosrc => 'dtof' },
887887
{ oid => '313', descr => 'convert int2 to int4',
888-
proname => 'int4', prorettype => 'int4', proargtypes => 'int2',
889-
prosrc => 'i2toi4' },
888+
proname => 'int4', proleakproof => 't', prorettype => 'int4',
889+
proargtypes => 'int2', prosrc => 'i2toi4' },
890890
{ oid => '314', descr => 'convert int4 to int2',
891891
proname => 'int2', prorettype => 'int2', proargtypes => 'int4',
892892
prosrc => 'i4toi2' },
893893
{ oid => '316', descr => 'convert int4 to float8',
894-
proname => 'float8', prorettype => 'float8', proargtypes => 'int4',
895-
prosrc => 'i4tod' },
894+
proname => 'float8', proleakproof => 't', prorettype => 'float8',
895+
proargtypes => 'int4', prosrc => 'i4tod' },
896896
{ oid => '317', descr => 'convert float8 to int4',
897897
proname => 'int4', prorettype => 'int4', proargtypes => 'float8',
898898
prosrc => 'dtoi4' },
899899
{ oid => '318', descr => 'convert int4 to float4',
900-
proname => 'float4', prorettype => 'float4', proargtypes => 'int4',
901-
prosrc => 'i4tof' },
900+
proname => 'float4', proleakproof => 't', prorettype => 'float4',
901+
proargtypes => 'int4', prosrc => 'i4tof' },
902902
{ oid => '319', descr => 'convert float4 to int4',
903903
proname => 'int4', prorettype => 'int4', proargtypes => 'float4',
904904
prosrc => 'ftoi4' },
@@ -1150,17 +1150,17 @@
11501150
proname => 'text', prorettype => 'text', proargtypes => 'bpchar',
11511151
prosrc => 'rtrim1' },
11521152
{ oid => '406', descr => 'convert name to text',
1153-
proname => 'text', prorettype => 'text', proargtypes => 'name',
1154-
prosrc => 'name_text' },
1153+
proname => 'text', proleakproof => 't', prorettype => 'text',
1154+
proargtypes => 'name', prosrc => 'name_text' },
11551155
{ oid => '407', descr => 'convert text to name',
1156-
proname => 'name', prorettype => 'name', proargtypes => 'text',
1157-
prosrc => 'text_name' },
1156+
proname => 'name', proleakproof => 't', prorettype => 'name',
1157+
proargtypes => 'text', prosrc => 'text_name' },
11581158
{ oid => '408', descr => 'convert name to char(n)',
11591159
proname => 'bpchar', prorettype => 'bpchar', proargtypes => 'name',
11601160
prosrc => 'name_bpchar' },
11611161
{ oid => '409', descr => 'convert char(n) to name',
1162-
proname => 'name', prorettype => 'name', proargtypes => 'bpchar',
1163-
prosrc => 'bpchar_name' },
1162+
proname => 'name', proleakproof => 't', prorettype => 'name',
1163+
proargtypes => 'bpchar', prosrc => 'bpchar_name' },
11641164

11651165
{ oid => '449', descr => 'hash',
11661166
proname => 'hashint2', prorettype => 'int4', proargtypes => 'int2',
@@ -1338,11 +1338,11 @@
13381338
proname => 'int4', prorettype => 'int4', proargtypes => 'int8',
13391339
prosrc => 'int84' },
13401340
{ oid => '481', descr => 'convert int4 to int8',
1341-
proname => 'int8', prorettype => 'int8', proargtypes => 'int4',
1342-
prosrc => 'int48' },
1341+
proname => 'int8', proleakproof => 't', prorettype => 'int8',
1342+
proargtypes => 'int4', prosrc => 'int48' },
13431343
{ oid => '482', descr => 'convert int8 to float8',
1344-
proname => 'float8', prorettype => 'float8', proargtypes => 'int8',
1345-
prosrc => 'i8tod' },
1344+
proname => 'float8', proleakproof => 't', prorettype => 'float8',
1345+
proargtypes => 'int8', prosrc => 'i8tod' },
13461346
{ oid => '483', descr => 'convert float8 to int8',
13471347
proname => 'int8', prorettype => 'int8', proargtypes => 'float8',
13481348
prosrc => 'dtoi8' },
@@ -1359,8 +1359,8 @@
13591359
proargtypes => 'anyarray int8', prosrc => 'hash_array_extended' },
13601360

13611361
{ oid => '652', descr => 'convert int8 to float4',
1362-
proname => 'float4', prorettype => 'float4', proargtypes => 'int8',
1363-
prosrc => 'i8tof' },
1362+
proname => 'float4', proleakproof => 't', prorettype => 'float4',
1363+
proargtypes => 'int8', prosrc => 'i8tof' },
13641364
{ oid => '653', descr => 'convert float4 to int8',
13651365
proname => 'int8', prorettype => 'int8', proargtypes => 'float4',
13661366
prosrc => 'ftoi8' },
@@ -1369,8 +1369,8 @@
13691369
proname => 'int2', prorettype => 'int2', proargtypes => 'int8',
13701370
prosrc => 'int82' },
13711371
{ oid => '754', descr => 'convert int2 to int8',
1372-
proname => 'int8', prorettype => 'int8', proargtypes => 'int2',
1373-
prosrc => 'int28' },
1372+
proname => 'int8', proleakproof => 't', prorettype => 'int8',
1373+
proargtypes => 'int2', prosrc => 'int28' },
13741374

13751375
{ oid => '655',
13761376
proname => 'namelt', proleakproof => 't', prorettype => 'bool',
@@ -2521,8 +2521,8 @@
25212521
proname => 'oid', prorettype => 'oid', proargtypes => 'int8',
25222522
prosrc => 'i8tooid' },
25232523
{ oid => '1288', descr => 'convert oid to int8',
2524-
proname => 'int8', prorettype => 'int8', proargtypes => 'oid',
2525-
prosrc => 'oidtoi8' },
2524+
proname => 'int8', proleakproof => 't', prorettype => 'int8',
2525+
proargtypes => 'oid', prosrc => 'oidtoi8' },
25262526

25272527
{ oid => '1291',
25282528
descr => 'trigger to suppress updates when new and old records match',
@@ -2782,8 +2782,8 @@
27822782
prosrc => 'textlen' },
27832783

27842784
{ oid => '1370', descr => 'convert time to interval',
2785-
proname => 'interval', prorettype => 'interval', proargtypes => 'time',
2786-
prosrc => 'time_interval' },
2785+
proname => 'interval', proleakproof => 't', prorettype => 'interval',
2786+
proargtypes => 'time', prosrc => 'time_interval' },
27872787
{ oid => '1372', descr => 'character length',
27882788
proname => 'char_length', prorettype => 'int4', proargtypes => 'bpchar',
27892789
prosrc => 'bpcharlen' },
@@ -2861,11 +2861,11 @@
28612861
# OIDS 1400 - 1499
28622862

28632863
{ oid => '1400', descr => 'convert varchar to name',
2864-
proname => 'name', prorettype => 'name', proargtypes => 'varchar',
2865-
prosrc => 'text_name' },
2864+
proname => 'name', proleakproof => 't', prorettype => 'name',
2865+
proargtypes => 'varchar', prosrc => 'text_name' },
28662866
{ oid => '1401', descr => 'convert name to varchar',
2867-
proname => 'varchar', prorettype => 'varchar', proargtypes => 'name',
2868-
prosrc => 'name_text' },
2867+
proname => 'varchar', proleakproof => 't', prorettype => 'varchar',
2868+
proargtypes => 'name', prosrc => 'name_text' },
28692869

28702870
{ oid => '1402', descr => 'current schema name',
28712871
proname => 'current_schema', provolatile => 's', proparallel => 'u',
@@ -3941,8 +3941,8 @@
39413941
proname => 'macaddr8_or', prorettype => 'macaddr8',
39423942
proargtypes => 'macaddr8 macaddr8', prosrc => 'macaddr8_or' },
39433943
{ oid => '4123', descr => 'convert macaddr to macaddr8',
3944-
proname => 'macaddr8', prorettype => 'macaddr8', proargtypes => 'macaddr',
3945-
prosrc => 'macaddrtomacaddr8' },
3944+
proname => 'macaddr8', proleakproof => 't', prorettype => 'macaddr8',
3945+
proargtypes => 'macaddr', prosrc => 'macaddrtomacaddr8' },
39463946
{ oid => '4124', descr => 'convert macaddr8 to macaddr',
39473947
proname => 'macaddr', prorettype => 'macaddr', proargtypes => 'macaddr8',
39483948
prosrc => 'macaddr8tomacaddr' },
@@ -4321,20 +4321,20 @@
43214321
proname => 'trim_scale', prorettype => 'numeric', proargtypes => 'numeric',
43224322
prosrc => 'numeric_trim_scale' },
43234323
{ oid => '1740', descr => 'convert int4 to numeric',
4324-
proname => 'numeric', prorettype => 'numeric', proargtypes => 'int4',
4325-
prosrc => 'int4_numeric' },
4324+
proname => 'numeric', proleakproof => 't', prorettype => 'numeric',
4325+
proargtypes => 'int4', prosrc => 'int4_numeric' },
43264326
{ oid => '1741', descr => 'base 10 logarithm',
43274327
proname => 'log', prolang => 'sql', prorettype => 'numeric',
43284328
proargtypes => 'numeric', prosrc => 'select pg_catalog.log(10, $1)' },
43294329
{ oid => '1481', descr => 'base 10 logarithm',
43304330
proname => 'log10', prolang => 'sql', prorettype => 'numeric',
43314331
proargtypes => 'numeric', prosrc => 'select pg_catalog.log(10, $1)' },
43324332
{ oid => '1742', descr => 'convert float4 to numeric',
4333-
proname => 'numeric', prorettype => 'numeric', proargtypes => 'float4',
4334-
prosrc => 'float4_numeric' },
4333+
proname => 'numeric', proleakproof => 't', prorettype => 'numeric',
4334+
proargtypes => 'float4', prosrc => 'float4_numeric' },
43354335
{ oid => '1743', descr => 'convert float8 to numeric',
4336-
proname => 'numeric', prorettype => 'numeric', proargtypes => 'float8',
4337-
prosrc => 'float8_numeric' },
4336+
proname => 'numeric', proleakproof => 't', prorettype => 'numeric',
4337+
proargtypes => 'float8', prosrc => 'float8_numeric' },
43384338
{ oid => '1744', descr => 'convert numeric to int4',
43394339
proname => 'int4', prorettype => 'int4', proargtypes => 'numeric',
43404340
prosrc => 'numeric_int4' },
@@ -4390,11 +4390,11 @@
43904390
proname => 'int8', prorettype => 'int8', proargtypes => 'numeric',
43914391
prosrc => 'numeric_int8' },
43924392
{ oid => '1781', descr => 'convert int8 to numeric',
4393-
proname => 'numeric', prorettype => 'numeric', proargtypes => 'int8',
4394-
prosrc => 'int8_numeric' },
4393+
proname => 'numeric', proleakproof => 't', prorettype => 'numeric',
4394+
proargtypes => 'int8', prosrc => 'int8_numeric' },
43954395
{ oid => '1782', descr => 'convert int2 to numeric',
4396-
proname => 'numeric', prorettype => 'numeric', proargtypes => 'int2',
4397-
prosrc => 'int2_numeric' },
4396+
proname => 'numeric', proleakproof => 't', prorettype => 'numeric',
4397+
proargtypes => 'int2', prosrc => 'int2_numeric' },
43984398
{ oid => '1783', descr => 'convert numeric to int2',
43994399
proname => 'int2', prorettype => 'int2', proargtypes => 'numeric',
44004400
prosrc => 'numeric_int2' },
@@ -7755,7 +7755,8 @@
77557755
{ oid => '2510', descr => 'get the prepared statements for this session',
77567756
proname => 'pg_prepared_statement', prorows => '1000', proretset => 't',
77577757
provolatile => 's', proparallel => 'r', prorettype => 'record',
7758-
proargtypes => '', proallargtypes => '{text,text,timestamptz,_regtype,bool,int8,int8}',
7758+
proargtypes => '',
7759+
proallargtypes => '{text,text,timestamptz,_regtype,bool,int8,int8}',
77597760
proargmodes => '{o,o,o,o,o,o,o}',
77607761
proargnames => '{name,statement,prepare_time,parameter_types,from_sql,generic_plans,custom_plans}',
77617762
prosrc => 'pg_prepared_statement' },
@@ -7933,11 +7934,11 @@
79337934
prosrc => 'pg_tablespace_databases' },
79347935

79357936
{ oid => '2557', descr => 'convert int4 to boolean',
7936-
proname => 'bool', prorettype => 'bool', proargtypes => 'int4',
7937-
prosrc => 'int4_bool' },
7937+
proname => 'bool', proleakproof => 't', prorettype => 'bool',
7938+
proargtypes => 'int4', prosrc => 'int4_bool' },
79387939
{ oid => '2558', descr => 'convert boolean to int4',
7939-
proname => 'int4', prorettype => 'int4', proargtypes => 'bool',
7940-
prosrc => 'bool_int4' },
7940+
proname => 'int4', proleakproof => 't', prorettype => 'int4',
7941+
proargtypes => 'bool', prosrc => 'bool_int4' },
79417942
{ oid => '2559', descr => 'current value from last used sequence',
79427943
proname => 'lastval', provolatile => 'v', proparallel => 'u',
79437944
prorettype => 'int8', proargtypes => '', prosrc => 'lastval' },

src/test/regress/expected/opr_sanity.out

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -572,6 +572,8 @@ int24ge(smallint,integer)
572572
int42ge(integer,smallint)
573573
oideq(oid,oid)
574574
oidne(oid,oid)
575+
float8(smallint)
576+
float4(smallint)
575577
nameeqtext(name,text)
576578
namelttext(name,text)
577579
nameletext(name,text)
@@ -610,6 +612,10 @@ float84lt(double precision,real)
610612
float84le(double precision,real)
611613
float84gt(double precision,real)
612614
float84ge(double precision,real)
615+
float8(real)
616+
int4(smallint)
617+
float8(integer)
618+
float4(integer)
613619
btint2cmp(smallint,smallint)
614620
btint4cmp(integer,integer)
615621
btfloat4cmp(real,real)
@@ -620,6 +626,9 @@ btnamecmp(name,name)
620626
bttextcmp(text,text)
621627
cash_cmp(money,money)
622628
btoidvectorcmp(oidvector,oidvector)
629+
text(name)
630+
name(text)
631+
name(character)
623632
text_larger(text,text)
624633
text_smaller(text,text)
625634
int8eq(bigint,bigint)
@@ -634,7 +643,10 @@ int84lt(bigint,integer)
634643
int84gt(bigint,integer)
635644
int84le(bigint,integer)
636645
int84ge(bigint,integer)
646+
int8(integer)
647+
float8(bigint)
637648
oidvectorne(oidvector,oidvector)
649+
float4(bigint)
638650
namelt(name,name)
639651
namele(name,name)
640652
namegt(name,name)
@@ -651,6 +663,7 @@ text_lt(text,text)
651663
text_le(text,text)
652664
text_gt(text,text)
653665
text_ge(text,text)
666+
int8(smallint)
654667
macaddr_eq(macaddr,macaddr)
655668
macaddr_lt(macaddr,macaddr)
656669
macaddr_le(macaddr,macaddr)
@@ -716,6 +729,7 @@ interval_ge(interval,interval)
716729
interval_gt(interval,interval)
717730
charlt("char","char")
718731
tidne(tid,tid)
732+
int8(oid)
719733
tideq(tid,tid)
720734
timestamptz_cmp(timestamp with time zone,timestamp with time zone)
721735
interval_cmp(interval,interval)
@@ -727,6 +741,9 @@ timetz_le(time with time zone,time with time zone)
727741
timetz_ge(time with time zone,time with time zone)
728742
timetz_gt(time with time zone,time with time zone)
729743
timetz_cmp(time with time zone,time with time zone)
744+
"interval"(time without time zone)
745+
name(character varying)
746+
"varchar"(name)
730747
circle_eq(circle,circle)
731748
circle_ne(circle,circle)
732749
circle_lt(circle,circle)
@@ -757,6 +774,11 @@ varbitcmp(bit varying,bit varying)
757774
boolle(boolean,boolean)
758775
boolge(boolean,boolean)
759776
btboolcmp(boolean,boolean)
777+
"numeric"(integer)
778+
"numeric"(real)
779+
"numeric"(double precision)
780+
"numeric"(bigint)
781+
"numeric"(smallint)
760782
int28eq(smallint,bigint)
761783
int28ne(smallint,bigint)
762784
int28lt(smallint,bigint)
@@ -803,6 +825,8 @@ btfloat48cmp(real,double precision)
803825
btfloat84cmp(double precision,real)
804826
md5(text)
805827
md5(bytea)
828+
bool(integer)
829+
int4(boolean)
806830
tidgt(tid,tid)
807831
tidlt(tid,tid)
808832
tidge(tid,tid)
@@ -837,6 +861,7 @@ macaddr8_gt(macaddr8,macaddr8)
837861
macaddr8_ge(macaddr8,macaddr8)
838862
macaddr8_ne(macaddr8,macaddr8)
839863
macaddr8_cmp(macaddr8,macaddr8)
864+
macaddr8(macaddr)
840865
xid8lt(xid8,xid8)
841866
xid8gt(xid8,xid8)
842867
xid8le(xid8,xid8)

0 commit comments

Comments
 (0)