From df0b82f15008228282a1abf149ff56b8a6ea3c74 Mon Sep 17 00:00:00 2001 From: Robert Watson Date: Thu, 27 Dec 2007 21:28:48 +0000 Subject: [PATCH] Compare kernel dump header magic with textdump magic using strncmp() rather than the memcmp() which is used for regular dumps: the textdump string is one character shorter, so we need to stop comparing at the end of the string. Use independent version checking logic for architecture-specific version number vs. textdump version number, as the version sequences may (someday) differ. Run into by: rrs --- sbin/savecore/savecore.c | 42 +++++++++++++++++++++++++++++----------- 1 file changed, 31 insertions(+), 11 deletions(-) diff --git a/sbin/savecore/savecore.c b/sbin/savecore/savecore.c index 72448a396573..77636488e9e0 100644 --- a/sbin/savecore/savecore.c +++ b/sbin/savecore/savecore.c @@ -419,12 +419,32 @@ DoFile(const char *savedir, const char *device) goto closefd; } istextdump = 0; - if (memcmp(kdhl.magic, TEXTDUMPMAGIC, sizeof kdhl.magic)) { + if (strncmp(kdhl.magic, TEXTDUMPMAGIC, sizeof kdhl) == 0) { if (verbose) printf("textdump magic on last dump header on %s\n", device); istextdump = 1; - } else if (memcmp(kdhl.magic, KERNELDUMPMAGIC, sizeof kdhl.magic)) { + if (dtoh32(kdhl.version) != KERNELDUMP_TEXT_VERSION) { + syslog(LOG_ERR, + "unknown version (%d) in last dump header on %s", + dtoh32(kdhl.version), device); + + status = STATUS_BAD; + if (force == 0) + goto closefd; + } + } else if (memcmp(kdhl.magic, KERNELDUMPMAGIC, sizeof kdhl.magic) == + 0) { + if (dtoh32(kdhl.version) != KERNELDUMPVERSION) { + syslog(LOG_ERR, + "unknown version (%d) in last dump header on %s", + dtoh32(kdhl.version), device); + + status = STATUS_BAD; + if (force == 0) + goto closefd; + } + } else { if (verbose) printf("magic mismatch on last dump header on %s\n", device); @@ -443,15 +463,15 @@ DoFile(const char *savedir, const char *device) syslog(LOG_ERR, "unable to force dump - bad magic"); goto closefd; } - } - if (dtoh32(kdhl.version) != KERNELDUMPVERSION) { - syslog(LOG_ERR, - "unknown version (%d) in last dump header on %s", - dtoh32(kdhl.version), device); - - status = STATUS_BAD; - if (force == 0) - goto closefd; + if (dtoh32(kdhl.version) != KERNELDUMPVERSION) { + syslog(LOG_ERR, + "unknown version (%d) in last dump header on %s", + dtoh32(kdhl.version), device); + + status = STATUS_BAD; + if (force == 0) + goto closefd; + } } nfound++;