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

Commit7f3b41c

Browse files
committed
Clear padding of PgStat_HashKey when handling pgstats entries
PgStat_HashKey is currently initialized in a way that could result inrandom data if the structure has any padding bytes. The structurehas no padding bytes currently, fortunately, but it could become aproblem should the structure change at some point in the future.The code is changed to use some memset(0) so as any padding would behandled properly, as it would be surprising to see random failures inthe pgstats entry lookups. PgStat_HashKey is a structure internal topgstats, and an ABI change could be possible in the scope of a bug fix,so backpatch down to 15 where this has been introduced.Author: Bertrand DrouvotReviewed-by: Jelte Fennema-Nio, Michael PaquierDiscussion:https://postgr.es/m/Zyb7RW1y9dVfO0UH@ip-10-97-1-34.eu-west-3.compute.internalBackpatch-through: 15
1 parent811f8d3 commit7f3b41c

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

‎src/backend/utils/activity/pgstat.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -822,6 +822,9 @@ pgstat_fetch_entry(PgStat_Kind kind, Oid dboid, Oid objoid)
822822

823823
pgstat_prep_snapshot();
824824

825+
/* clear padding */
826+
memset(&key,0,sizeof(structPgStat_HashKey));
827+
825828
key.kind=kind;
826829
key.dboid=dboid;
827830
key.objoid=objoid;

‎src/backend/utils/activity/pgstat_shmem.c

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -406,11 +406,18 @@ PgStat_EntryRef *
406406
pgstat_get_entry_ref(PgStat_Kindkind,Oiddboid,Oidobjoid,boolcreate,
407407
bool*created_entry)
408408
{
409-
PgStat_HashKeykey= {.kind=kind,.dboid=dboid,.objoid=objoid};
409+
PgStat_HashKeykey;
410410
PgStatShared_HashEntry*shhashent;
411411
PgStatShared_Common*shheader=NULL;
412412
PgStat_EntryRef*entry_ref;
413413

414+
/* clear padding */
415+
memset(&key,0,sizeof(structPgStat_HashKey));
416+
417+
key.kind=kind;
418+
key.dboid=dboid;
419+
key.objoid=objoid;
420+
414421
/*
415422
* passing in created_entry only makes sense if we possibly could create
416423
* entry.
@@ -881,10 +888,17 @@ pgstat_drop_database_and_contents(Oid dboid)
881888
bool
882889
pgstat_drop_entry(PgStat_Kindkind,Oiddboid,Oidobjoid)
883890
{
884-
PgStat_HashKeykey= {.kind=kind,.dboid=dboid,.objoid=objoid};
891+
PgStat_HashKeykey;
885892
PgStatShared_HashEntry*shent;
886893
boolfreed= true;
887894

895+
/* clear padding */
896+
memset(&key,0,sizeof(structPgStat_HashKey));
897+
898+
key.kind=kind;
899+
key.dboid=dboid;
900+
key.objoid=objoid;
901+
888902
/* delete local reference */
889903
if (pgStatEntryRefHash)
890904
{

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp