From 4c05286a613b1b9ac075892dd1cb14b59104df9f Mon Sep 17 00:00:00 2001 From: csjp Date: Sun, 15 Jan 2006 20:30:13 +0000 Subject: Validate that the supplied file is not empty before trying mmap(2) it and access the pages associated with it. Submitted by: Wojciech A. Koszek PR: bin/91411 MFC after: 1 week --- lib/libkvm/kvm.c | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'lib/libkvm') diff --git a/lib/libkvm/kvm.c b/lib/libkvm/kvm.c index 9e97a78..1bea13c 100644 --- a/lib/libkvm/kvm.c +++ b/lib/libkvm/kvm.c @@ -179,6 +179,11 @@ _kvm_open(kd, uf, mf, flag, errout) _kvm_syserr(kd, kd->program, "%s", mf); goto failed; } + if (S_ISREG(st.st_mode) && st.st_size <= 0) { + errno = EINVAL; + _kvm_syserr(kd, kd->program, "empty file"); + goto failed; + } if (fcntl(kd->pmfd, F_SETFD, FD_CLOEXEC) < 0) { _kvm_syserr(kd, kd->program, "%s", mf); goto failed; -- cgit v1.1