Fix race condition in pg_ctl reading postmaster.pid.

Heikki Linnakangas <heikki.linnakangas@iki.fi>

Commit: 1c95b5eea6bec742d5d6ee097c55690712dd3be6
Author: Heikki Linnakangas <heikki.linnakangas@iki.fi>
Date: 2012-10-15T07:54:33Z
Releases: 9.0.11
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.

Files

PathChange+/−
src/bin/initdb/initdb.c modified +5 −4
src/bin/pg_ctl/pg_ctl.c modified +58 −30