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

Commit7d85d87

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 parent0704aed commit7d85d87

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
@@ -938,6 +938,9 @@ pgstat_fetch_entry(PgStat_Kind kind, Oid dboid, uint64 objid)
938938

939939
pgstat_prep_snapshot();
940940

941+
/* clear padding */
942+
memset(&key,0,sizeof(structPgStat_HashKey));
943+
941944
key.kind=kind;
942945
key.dboid=dboid;
943946
key.objid=objid;

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

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -432,11 +432,18 @@ PgStat_EntryRef *
432432
pgstat_get_entry_ref(PgStat_Kindkind,Oiddboid,uint64objid,boolcreate,
433433
bool*created_entry)
434434
{
435-
PgStat_HashKeykey= {.kind=kind,.dboid=dboid,.objid=objid};
435+
PgStat_HashKeykey;
436436
PgStatShared_HashEntry*shhashent;
437437
PgStatShared_Common*shheader=NULL;
438438
PgStat_EntryRef*entry_ref;
439439

440+
/* clear padding */
441+
memset(&key,0,sizeof(structPgStat_HashKey));
442+
443+
key.kind=kind;
444+
key.dboid=dboid;
445+
key.objid=objid;
446+
440447
/*
441448
* passing in created_entry only makes sense if we possibly could create
442449
* entry.
@@ -908,10 +915,17 @@ pgstat_drop_database_and_contents(Oid dboid)
908915
bool
909916
pgstat_drop_entry(PgStat_Kindkind,Oiddboid,uint64objid)
910917
{
911-
PgStat_HashKeykey= {.kind=kind,.dboid=dboid,.objid=objid};
918+
PgStat_HashKeykey;
912919
PgStatShared_HashEntry*shent;
913920
boolfreed= true;
914921

922+
/* clear padding */
923+
memset(&key,0,sizeof(structPgStat_HashKey));
924+
925+
key.kind=kind;
926+
key.dboid=dboid;
927+
key.objid=objid;
928+
915929
/* delete local reference */
916930
if (pgStatEntryRefHash)
917931
{

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp