diff options
author | Susan LoVerso <sue@wiredtiger.com> | 2015-05-14 10:47:41 -0400 |
---|---|---|
committer | Susan LoVerso <sue@wiredtiger.com> | 2015-05-14 10:47:41 -0400 |
commit | a1d1334260de46879aae637f1b67c7bbe3a59fd6 (patch) | |
tree | 17c9c8e570db5112dc79a4544f132befa6883a01 | |
parent | ac898d41d66d4916c2ba7b33432210c06a41244a (diff) | |
download | mongo-a1d1334260de46879aae637f1b67c7bbe3a59fd6.tar.gz |
Check magic and version numbers in log files when first opening them.
-rw-r--r-- | src/log/log.c | 42 |
1 files changed, 36 insertions, 6 deletions
diff --git a/src/log/log.c b/src/log/log.c index 4a0b8db381a..8c13b177abf 100644 --- a/src/log/log.c +++ b/src/log/log.c @@ -500,20 +500,50 @@ static int __log_openfile(WT_SESSION_IMPL *session, int ok_create, WT_FH **fh, const char *file_prefix, uint32_t id) { - WT_DECL_ITEM(path); + WT_DECL_ITEM(buf); WT_DECL_RET; + WT_LOG *log; + WT_LOG_DESC *desc; + WT_LOG_RECORD *logrec; + uint32_t allocsize; - WT_RET(__wt_scr_alloc(session, 0, &path)); - WT_ERR(__log_filename(session, id, file_prefix, path)); + log = S2C(session)->log; + if (log == NULL) + allocsize = LOG_ALIGN; + else + allocsize = log->allocsize; + WT_RET(__wt_scr_alloc(session, 0, &buf)); + WT_ERR(__log_filename(session, id, file_prefix, buf)); WT_ERR(__wt_verbose(session, WT_VERB_LOG, - "opening log %s", (const char *)path->data)); + "opening log %s", (const char *)buf->data)); WT_ERR(__wt_open( - session, path->data, ok_create, 0, WT_FILE_TYPE_LOG, fh)); + session, buf->data, ok_create, 0, WT_FILE_TYPE_LOG, fh)); /* * XXX - if we are not creating the file, we should verify the * log file header record for the magic number and versions here. */ -err: __wt_scr_free(session, &path); + if (!ok_create) { + __wt_scr_free(session, &buf); + WT_ERR(__wt_scr_alloc(session, allocsize, &buf)); + memset(buf->mem, 0, allocsize); + WT_ERR(__wt_read(session, *fh, 0, allocsize, buf->mem)); + logrec = (WT_LOG_RECORD *)buf->mem; + desc = (WT_LOG_DESC *)logrec->record; + if (desc->log_magic != WT_LOG_MAGIC) + WT_PANIC_RET(session, WT_ERROR, + "log file %s corrupted: Bad magic number %" PRIu32, + (*fh)->name, desc->log_magic); + if (desc->majorv > WT_LOG_MAJOR_VERSION || + (desc->majorv == WT_LOG_MAJOR_VERSION && + desc->minorv > WT_LOG_MINOR_VERSION)) + WT_ERR_MSG(session, WT_ERROR, + "unsupported WiredTiger file version: this build " + " only supports major/minor versions up to %d/%d, " + " and the file is version %d/%d", + WT_LOG_MAJOR_VERSION, WT_LOG_MINOR_VERSION, + desc->majorv, desc->minorv); + } +err: __wt_scr_free(session, &buf); return (ret); } |