diff options
author | Peter Eisentraut <peter_e@gmx.net> | 2016-09-28 12:00:00 -0400 |
---|---|---|
committer | Peter Eisentraut <peter_e@gmx.net> | 2016-09-28 12:00:00 -0400 |
commit | e79e6c4da152154544913b38354b98d07b65e411 (patch) | |
tree | 5a0c8a6bff3422fc263704dd8dc4bd733c822d4a /src/common/controldata_utils.c | |
parent | 308985b0b404a5891a1a629f38cc46c2b2dcb4be (diff) |
Fix CRC check handling in get_controlfile
The previous patch broke this by returning NULL for a failed CRC check,
which pg_controldata would then try to read. Fix by returning the
result of the CRC check in a separate argument.
Michael Paquier and myself
Diffstat (limited to 'src/common/controldata_utils.c')
-rw-r--r-- | src/common/controldata_utils.c | 19 |
1 files changed, 9 insertions, 10 deletions
diff --git a/src/common/controldata_utils.c b/src/common/controldata_utils.c index f218d2558c1..cbdae052a75 100644 --- a/src/common/controldata_utils.c +++ b/src/common/controldata_utils.c @@ -29,21 +29,24 @@ #include "port/pg_crc32c.h" /* - * get_controlfile(char *DataDir, const char *progname) + * get_controlfile(char *DataDir, const char *progname, bool *crc_ok_p) * - * Get controlfile values. The caller is responsible - * for pfreeing the result. + * Get controlfile values. The result is returned as a palloc'd copy of the + * control file data. * - * Returns NULL if the CRC did not match. + * crc_ok_p can be used by the caller to see whether the CRC of the control + * file data is correct. */ ControlFileData * -get_controlfile(const char *DataDir, const char *progname) +get_controlfile(const char *DataDir, const char *progname, bool *crc_ok_p) { ControlFileData *ControlFile; int fd; char ControlFilePath[MAXPGPATH]; pg_crc32c crc; + AssertArg(crc_ok_p); + ControlFile = palloc(sizeof(ControlFileData)); snprintf(ControlFilePath, MAXPGPATH, "%s/global/pg_control", DataDir); @@ -83,11 +86,7 @@ get_controlfile(const char *DataDir, const char *progname) offsetof(ControlFileData, crc)); FIN_CRC32C(crc); - if (!EQ_CRC32C(crc, ControlFile->crc)) - { - pfree(ControlFile); - return NULL; - } + *crc_ok_p = EQ_CRC32C(crc, ControlFile->crc); /* Make sure the control file is valid byte order. */ if (ControlFile->pg_control_version % 65536 == 0 && |