* Dave Anderson <anderson(a)redhat.com> [2007-09-25 16:58]:
Bernhard Walle wrote:
> * Dave Anderson <anderson(a)redhat.com> [2007-09-25 15:59]:
>> I understand the concern about the read error message, but maybe
>> a better way to do it would be to just issue a WARNING message?
> That's a valid point. So what about this one:
I'm going to defer this one for now -- I'm trying to get a
release out today.
Of course, nothing urgent.
Anyway, the function wouldn't need to return anything, it
only works for netdumps or kdumps and not the other dumpfile
types (not that I'm planning on implementing it on those
other types...), I'd really need to test it thoroughly, etc...
I just left the return value for debugging reasons. But it's cleaner
to remove it, you're right:
Signed-off-by: Bernhard Walle <bwalle(a)suse.de>
---
defs.h | 1 +
netdump.c | 41 +++++++++++++++++++++++++++++++++++++++++
2 files changed, 42 insertions(+)
--- a/defs.h
+++ b/defs.h
@@ -16,6 +16,7 @@
* GNU General Public License for more details.
*/
+#define _LARGEFILE64_SOURCE 1 /* stat64() */
#ifndef GDB_COMMON
#include <stdio.h>
--- a/netdump.c
+++ b/netdump.c
@@ -33,6 +33,45 @@ static physaddr_t xen_kdump_p2m(physaddr
#define ELFREAD 0
#define MIN_PAGE_SIZE (4096)
+
+
+static void
+check_netdump_filesize(char *file)
+{
+ uint64_t max_file_offset = 0;
+ struct pt_load_segment *pls;
+ struct stat64 stat;
+ int i, ret;
+
+
+ /* find the maximum file offset */
+ for (i = 0; i < nd->num_pt_load_segments; i++) {
+ uint64_t end, size;
+
+ pls = &nd->pt_load_segments[i];
+
+ size = pls->phys_end - pls->phys_start;
+ end = pls->file_offset + size;
+
+ if (end > max_file_offset)
+ max_file_offset = end;
+ }
+
+ ret = stat64(file, &stat);
+ if (ret < 0) {
+ error(WARNING, "Cannot stat64 on %s: %s\n. Checking of file "
+ "size disabled", file, strerror(errno));
+ return;
+ }
+
+ if (max_file_offset > stat.st_size) {
+ error(WARNING, "File %s is too short:\n"
+ "Must be %lld bytes but is only "
+ "%lld bytes long.\n",
+ file, max_file_offset, stat.st_size);
+ return;
+ }
+}
/*
* Determine whether a file is a netdump/diskdump/kdump creation,
@@ -267,6 +306,8 @@ is_netdump(char *file, ulong source_quer
if (CRASHDEBUG(1))
netdump_memory_dump(fp);
+ check_netdump_filesize(file);
+
return nd->header_size;
bailout: