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

Commita45ed97

Browse files
committed
Fix memory overrun when querying pg_stat_slru
pg_stat_get_slru() in pgstatfuncs.c would point to one element after theend of the array PgStat_SLRUStats when finishing to scan its entries.This had no direct consequences as no data from the extra memory areawas read, but static analyzers would rightfully complain here. So let'sbe clean.While on it, this adds one regression test in the area reserved forsystem views.Reported-by: Alexander Kozhemyakin, via AddressSanitizerAuthor: Kyotaro HoriguchiDiscussion:https://postgr.es/m/17280-37da556e86032070@postgresql.orgBackpatch-through: 13
1 parent3354746 commita45ed97

File tree

3 files changed

+12
-1
lines changed

3 files changed

+12
-1
lines changed

‎src/backend/utils/adt/pgstatfuncs.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1911,14 +1911,15 @@ pg_stat_get_slru(PG_FUNCTION_ARGS)
19111911
/* for each row */
19121912
Datumvalues[PG_STAT_GET_SLRU_COLS];
19131913
boolnulls[PG_STAT_GET_SLRU_COLS];
1914-
PgStat_SLRUStatsstat=stats[i];
1914+
PgStat_SLRUStatsstat;
19151915
constchar*name;
19161916

19171917
name=pgstat_slru_name(i);
19181918

19191919
if (!name)
19201920
break;
19211921

1922+
stat=stats[i];
19221923
MemSet(values,0,sizeof(values));
19231924
MemSet(nulls,0,sizeof(nulls));
19241925

‎src/test/regress/expected/sysviews.out

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,13 @@ select count(*) >= 0 as ok from pg_prepared_xacts;
7676
t
7777
(1 row)
7878

79+
-- There will surely be at least one SLRU cache
80+
select count(*) > 0 as ok from pg_stat_slru;
81+
ok
82+
----
83+
t
84+
(1 row)
85+
7986
-- There must be only one record
8087
select count(*) = 1 as ok from pg_stat_wal;
8188
ok

‎src/test/regress/sql/sysviews.sql

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ select count(*) = 0 as ok from pg_prepared_statements;
3737
-- See also prepared_xacts.sql
3838
selectcount(*)>=0as okfrom pg_prepared_xacts;
3939

40+
-- There will surely be at least one SLRU cache
41+
selectcount(*)>0as okfrom pg_stat_slru;
42+
4043
-- There must be only one record
4144
selectcount(*)=1as okfrom pg_stat_wal;
4245

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp