File kdump-fix-extractKernelConfigELF.patch of Package kdump
From: Petr Tesarik <ptesarik@suse.com>
Date: Fri Aug 28 11:03:25 2015 +0200
Subject: Fix KernelTool::extractKernelConfigELF if config not present
References: bsc#941088
Patch-mainline: v0.8.16
Git-commit: dc2a2aad6f3d93b1c7b609e8faf419e0730bdd1a
The begin/end offsets are initialized to 0, but the check is for
negative, so the method does not fail if no config is found.
Instead it tries to allocate negative buffer, throwing an exception
of type std::bad_alloc.
Signed-off-by: Petr Tesarik <ptesarik@suse.com>
diff --git a/kdumptool/kerneltool.cc b/kdumptool/kerneltool.cc
index 33998ba..a85b112 100644
--- a/kdumptool/kerneltool.cc
+++ b/kdumptool/kerneltool.cc
@@ -517,14 +517,14 @@ string KernelTool::extractKernelConfigELF() const
// search for the begin and end offests first
off_t fileoffset = 0;
ssize_t chars_read;
- off_t begin_offset = 0, end_offset = 0;
+ off_t begin_offset = -1, end_offset = -1;
while ((chars_read = gzread(fp, buffer+MAGIC_LEN, BUFSIZ-MAGIC_LEN)) > 0) {
- if (begin_offset == 0) {
+ if (begin_offset < 0) {
ssize_t pos = Util::findBytes(buffer, BUFSIZ, magic_start, MAGIC_LEN);
if (pos > 0) {
begin_offset = fileoffset + pos - MAGIC_LEN;
}
- } else if (end_offset == 0) {
+ } else if (end_offset < 0) {
ssize_t pos = Util::findBytes(buffer, BUFSIZ, magic_end, MAGIC_LEN);
if (pos > 0) {
end_offset = fileoffset + pos - MAGIC_LEN;