Skip to content
This repository has been archived by the owner on Oct 6, 2022. It is now read-only.

Commit

Permalink
Fix size of control file generated after rewind
Browse files Browse the repository at this point in the history
Use a proper zero-padded buffer to write control file and prevent
EOF-related errors that may occur when reading it.
  • Loading branch information
Michael Paquier committed Jul 24, 2014
1 parent 559655d commit f530910
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions pg_rewind.c
Original file line number Diff line number Diff line change
Expand Up @@ -496,8 +496,8 @@ digestControlFile(ControlFileData *ControlFile, char *src, size_t size)
static void
updateControlFile(ControlFileData *ControlFile, char *datadir)
{

char path[MAXPGPATH];
char buffer[PG_CONTROL_SIZE];
FILE *fp;

if (dry_run)
Expand All @@ -510,6 +510,14 @@ updateControlFile(ControlFileData *ControlFile, char *datadir)
offsetof(ControlFileData, crc));
FIN_CRC32(ControlFile->crc);

/*
* Write out PG_CONTROL_SIZE bytes into pg_control by zero-padding
* the excess over sizeof(ControlFileData) to avoid premature EOF
* related errors when reading it.
*/
memset(buffer, 0, PG_CONTROL_SIZE);
memcpy(buffer, ControlFile, sizeof(ControlFileData));

snprintf(path, MAXPGPATH,
"%s/global/pg_control", datadir);

Expand All @@ -519,7 +527,7 @@ updateControlFile(ControlFileData *ControlFile, char *datadir)
exit(1);
}

if (fwrite(ControlFile, 1,
if (fwrite(buffer, 1,
PG_CONTROL_SIZE, fp) != PG_CONTROL_SIZE)
{
fprintf(stderr,"Could not write the pg_control file\n");
Expand Down

0 comments on commit f530910

Please sign in to comment.