forked frompostgres/postgres
- Notifications
You must be signed in to change notification settings - Fork6
Commit5265e91
committed
Make MemoryContextContains work correctly again
c6e0fe1 recently changed the way we store headers for allocated chunksof memory. Prior to that commit, we stored a pointer to the owningMemoryContext directly prior to the pointer to the allocated memory.That's no longer true andc6e0fe1 neglected to updateMemoryContextContains() so that it correctly obtains the owning contextwith the new method.A side effect of this change andc6e0fe1, in general, is that it's evenless safe than it was previously to pass MemoryContextContains() anarbitrary pointer which was not allocated by one of our MemoryContexts.Previously some comments in MemoryContextContains() seemed to indicatethat the worst that could happen by passing an arbitrary pointer would bea false positive return value. It seems to me that this was a ratherwishful outlook as we subsequently proceeded to subtract sizeof(void *)from the given pointer and then dereferenced that memory. So it seemsquite likely that we could have segfaulted instead of returning a falsepositive. However, it's not impossible that the memory sizeof(void *)bytes before the pointer could have been owned by the process, but it'sfar less likely to work now as obtaining a pointer to the owningMemoryContext is less direct than beforec6e0fe1 and will access memorythat's possibly much further away to obtain the owning MemoryContext.Because of this, I took the liberty of updating the comment to warnagainst any future usages of the function and checked the existing coreusages to ensure that we only ever pass in a pointer to memory allocatedby a MemoryContext.Extension authors updating their code for PG16 who are usingMemoryContextContains should check to ensure that only NULL pointers andpointers to chunks allocated with a MemoryContext will ever be passed toMemoryContextContains.Reported-by: Andres FreundDiscussion:https://postgr.es/m/20220905230949.kb3x2fkpfwtngz43@awork3.anarazel.de1 parent3fe76ab commit5265e91
1 file changed
+36
-9
lines changedOriginal file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
482 | 482 |
| |
483 | 483 |
| |
484 | 484 |
| |
| 485 | + | |
| 486 | + | |
| 487 | + | |
| 488 | + | |
| 489 | + | |
| 490 | + | |
| 491 | + | |
| 492 | + | |
| 493 | + | |
485 | 494 |
| |
486 | 495 |
| |
487 | 496 |
| |
| |||
809 | 818 |
| |
810 | 819 |
| |
811 | 820 |
| |
812 |
| - | |
813 |
| - | |
814 |
| - | |
815 |
| - | |
816 |
| - | |
| 821 | + | |
| 822 | + | |
| 823 | + | |
| 824 | + | |
817 | 825 |
| |
818 | 826 |
| |
819 | 827 |
| |
820 | 828 |
| |
821 | 829 |
| |
822 | 830 |
| |
823 | 831 |
| |
824 |
| - | |
825 |
| - | |
826 |
| - | |
| 832 | + | |
| 833 | + | |
827 | 834 |
| |
828 | 835 |
| |
829 | 836 |
| |
| |||
835 | 842 |
| |
836 | 843 |
| |
837 | 844 |
| |
838 |
| - | |
| 845 | + | |
839 | 846 |
| |
840 | 847 |
| |
841 | 848 |
| |
| |||
953 | 960 |
| |
954 | 961 |
| |
955 | 962 |
| |
| 963 | + | |
| 964 | + | |
956 | 965 |
| |
957 | 966 |
| |
958 | 967 |
| |
| |||
991 | 1000 |
| |
992 | 1001 |
| |
993 | 1002 |
| |
| 1003 | + | |
| 1004 | + | |
994 | 1005 |
| |
995 | 1006 |
| |
996 | 1007 |
| |
| |||
1029 | 1040 |
| |
1030 | 1041 |
| |
1031 | 1042 |
| |
| 1043 | + | |
| 1044 | + | |
1032 | 1045 |
| |
1033 | 1046 |
| |
1034 | 1047 |
| |
| |||
1070 | 1083 |
| |
1071 | 1084 |
| |
1072 | 1085 |
| |
| 1086 | + | |
| 1087 | + | |
1073 | 1088 |
| |
1074 | 1089 |
| |
1075 | 1090 |
| |
| |||
1153 | 1168 |
| |
1154 | 1169 |
| |
1155 | 1170 |
| |
| 1171 | + | |
| 1172 | + | |
1156 | 1173 |
| |
1157 | 1174 |
| |
1158 | 1175 |
| |
| |||
1186 | 1203 |
| |
1187 | 1204 |
| |
1188 | 1205 |
| |
| 1206 | + | |
| 1207 | + | |
1189 | 1208 |
| |
1190 | 1209 |
| |
1191 | 1210 |
| |
| |||
1225 | 1244 |
| |
1226 | 1245 |
| |
1227 | 1246 |
| |
| 1247 | + | |
| 1248 | + | |
1228 | 1249 |
| |
1229 | 1250 |
| |
1230 | 1251 |
| |
| |||
1278 | 1299 |
| |
1279 | 1300 |
| |
1280 | 1301 |
| |
| 1302 | + | |
| 1303 | + | |
1281 | 1304 |
| |
1282 | 1305 |
| |
1283 | 1306 |
| |
| |||
1313 | 1336 |
| |
1314 | 1337 |
| |
1315 | 1338 |
| |
| 1339 | + | |
| 1340 | + | |
1316 | 1341 |
| |
1317 | 1342 |
| |
1318 | 1343 |
| |
| |||
1352 | 1377 |
| |
1353 | 1378 |
| |
1354 | 1379 |
| |
| 1380 | + | |
| 1381 | + | |
1355 | 1382 |
| |
1356 | 1383 |
| |
1357 | 1384 |
| |
|
0 commit comments
Comments
(0)