Re: [PATCH] Add file size check at the beginning

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



* Dave Anderson <anderson@xxxxxxxxxx> [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:


Signed-off-by: Bernhard Walle <bwalle@xxxxxxx>

---
 defs.h    |    1 +
 netdump.c |   43 +++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 44 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,47 @@ static physaddr_t xen_kdump_p2m(physaddr
 #define ELFREAD  0
 
 #define MIN_PAGE_SIZE (4096)
+
+
+static int
+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 FALSE;
+	}
+
+	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 FALSE;
+	}
+
+	return TRUE;
+}
 	
 /*
  *  Determine whether a file is a netdump/diskdump/kdump creation, 
@@ -267,6 +308,8 @@ is_netdump(char *file, ulong source_quer
 	if (CRASHDEBUG(1))
 		netdump_memory_dump(fp);
 
+	check_netdump_filesize(file);
+
 	return nd->header_size;
 
 bailout:

--
Crash-utility mailing list
Crash-utility@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/crash-utility

[Index of Archives]     [Fedora Development]     [Fedora Desktop]     [Fedora SELinux]     [Yosemite News]     [KDE Users]     [Fedora Tools]

 

Powered by Linux