Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit99b0c5d

Browse files
committed
Avoid direct C access to possibly-null pg_subscription_rel.srsublsn.
This coding technique is unsafe, since we'd be accessing off the endof the tuple if the field is null. SIGSEGV is pretty improbable, butperhaps not impossible. Also, returning garbage for the LSN doesn'tseem like a great idea, even if callers aren't looking at it today.Also update docs to point out explicitly thatpg_subscription.subslotname and pg_subscription_rel.srsublsncan be null.Perhaps we should mark these two fields BKI_FORCE_NULL, so thatthey'd be correctly labeled in databases that are initdb'd in thefuture. But we can't force that for existing databases, and onbalance it's not too clear that having a mix of different catalogcontents in the field would be wise.Apply to v10 (where this code came in) through v12. Alreadyfixed in v13 and HEAD.Discussion:https://postgr.es/m/732838.1595278439@sss.pgh.pa.us
1 parent855195a commit99b0c5d

File tree

3 files changed

+33
-7
lines changed

3 files changed

+33
-7
lines changed

‎doc/src/sgml/catalogs.sgml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6695,8 +6695,9 @@ SCRAM-SHA-256$<replaceable>&lt;iteration count&gt;</replaceable>:<replaceable>&l
66956695
<entry><structfield>subslotname</structfield></entry>
66966696
<entry><type>name</type></entry>
66976697
<entry></entry>
6698-
<entry>Name of the replication slot in the upstream database. Also used
6699-
for local replication origin name.</entry>
6698+
<entry>Name of the replication slot in the upstream database (also used
6699+
for the local replication origin name);
6700+
null represents <literal>NONE</literal></entry>
67006701
</row>
67016702

67026703
<row>
@@ -6778,7 +6779,9 @@ SCRAM-SHA-256$<replaceable>&lt;iteration count&gt;</replaceable>:<replaceable>&l
67786779
<entry><type>pg_lsn</type></entry>
67796780
<entry></entry>
67806781
<entry>
6781-
End LSN for <literal>s</literal> and <literal>r</literal> states.
6782+
Remote LSN of the state change used for synchronization coordination
6783+
when in <literal>s</literal> or <literal>r</literal> states,
6784+
otherwise null
67826785
</entry>
67836786
</row>
67846787
</tbody>

‎src/backend/catalog/pg_subscription.c

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -457,13 +457,20 @@ GetSubscriptionRelations(Oid subid)
457457
{
458458
Form_pg_subscription_relsubrel;
459459
SubscriptionRelState*relstate;
460+
Datumd;
461+
boolisnull;
460462

461463
subrel= (Form_pg_subscription_rel)GETSTRUCT(tup);
462464

463465
relstate= (SubscriptionRelState*)palloc(sizeof(SubscriptionRelState));
464466
relstate->relid=subrel->srrelid;
465467
relstate->state=subrel->srsubstate;
466-
relstate->lsn=subrel->srsublsn;
468+
d=SysCacheGetAttr(SUBSCRIPTIONRELMAP,tup,
469+
Anum_pg_subscription_rel_srsublsn,&isnull);
470+
if (isnull)
471+
relstate->lsn=InvalidXLogRecPtr;
472+
else
473+
relstate->lsn=DatumGetLSN(d);
467474

468475
res=lappend(res,relstate);
469476
}
@@ -509,13 +516,20 @@ GetSubscriptionNotReadyRelations(Oid subid)
509516
{
510517
Form_pg_subscription_relsubrel;
511518
SubscriptionRelState*relstate;
519+
Datumd;
520+
boolisnull;
512521

513522
subrel= (Form_pg_subscription_rel)GETSTRUCT(tup);
514523

515524
relstate= (SubscriptionRelState*)palloc(sizeof(SubscriptionRelState));
516525
relstate->relid=subrel->srrelid;
517526
relstate->state=subrel->srsubstate;
518-
relstate->lsn=subrel->srsublsn;
527+
d=SysCacheGetAttr(SUBSCRIPTIONRELMAP,tup,
528+
Anum_pg_subscription_rel_srsublsn,&isnull);
529+
if (isnull)
530+
relstate->lsn=InvalidXLogRecPtr;
531+
else
532+
relstate->lsn=DatumGetLSN(d);
519533

520534
res=lappend(res,relstate);
521535
}

‎src/include/catalog/pg_subscription_rel.h

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,17 @@ CATALOG(pg_subscription_rel,6102,SubscriptionRelRelationId) BKI_WITHOUT_OIDS
3434
Oidsrsubid;/* Oid of subscription */
3535
Oidsrrelid;/* Oid of relation */
3636
charsrsubstate;/* state of the relation in subscription */
37-
XLogRecPtrsrsublsn;/* remote lsn of the state change used for
38-
* synchronization coordination */
37+
38+
/*
39+
* Although srsublsn is a fixed-width type, it is allowed to be NULL, so
40+
* we prevent direct C code access to it just as for a varlena field.
41+
*/
42+
#ifdefCATALOG_VARLEN/* variable-length fields start here */
43+
44+
XLogRecPtrsrsublsn;/* remote LSN of the state change used for
45+
* synchronization coordination, or NULL if
46+
* not valid */
47+
#endif
3948
}FormData_pg_subscription_rel;
4049

4150
typedefFormData_pg_subscription_rel*Form_pg_subscription_rel;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp