pgsql: Fix race condition in pg_ctl reading postmaster.pid. - Mailing list pgsql-committers

From Heikki Linnakangas
Subject pgsql: Fix race condition in pg_ctl reading postmaster.pid.
Date
Msg-id E1TNfac-0008O2-TA@gemulon.postgresql.org
Whole thread Raw
List pgsql-committers
Fix race condition in pg_ctl reading postmaster.pid.

If postmaster changed postmaster.pid while pg_ctl was reading it, pg_ctl
could overrun the buffer it allocated for the file. Fix by reading the
whole file to memory with one read() call.

initdb contains an identical copy of the readfile() function, but the files
that initdb reads are static, not modified concurrently. Nevertheless, add
a simple bounds-check there, if only to silence static analysis tools.

Per report from Dave Vitek. Backpatch to all supported branches.

Branch
------
REL8_4_STABLE

Details
-------
http://git.postgresql.org/pg/commitdiff/6d934e4aaec1e7712e088a48d9fc02acc5be4d25

Modified Files
--------------
src/bin/initdb/initdb.c |   12 +++----
src/bin/pg_ctl/pg_ctl.c |   88 +++++++++++++++++++++++++++++++----------------
2 files changed, 63 insertions(+), 37 deletions(-)


pgsql-committers by date:

Previous
From: Tom Lane
Date:
Subject: pgsql: Split up process latch initialization for more-fail-soft behavio
Next
From: Heikki Linnakangas
Date:
Subject: pgsql: Fix race condition in pg_ctl reading postmaster.pid.