diff options
author | Ray Lai <ray@cvs.openbsd.org> | 2007-08-02 23:10:06 +0000 |
---|---|---|
committer | Ray Lai <ray@cvs.openbsd.org> | 2007-08-02 23:10:06 +0000 |
commit | 62480a7640d733b65e68d6a1d3d61e8a6f1a6dff (patch) | |
tree | badea9f1034cecd5edcc71627c7b6f6179bfb2fa /distrib | |
parent | 6c548342db6815fde404de21855b7fcb582c7cf1 (diff) |
In case the image size is too large, warn and exit instead of
truncating.
Initial diff from Rainer Giedat <rainer at staatssicherheit dot
com>.
OK millert and deraadt.
Diffstat (limited to 'distrib')
-rw-r--r-- | distrib/common/elfrdsetroot.c | 14 | ||||
-rw-r--r-- | distrib/common/rdsetroot.c | 15 |
2 files changed, 27 insertions, 2 deletions
diff --git a/distrib/common/elfrdsetroot.c b/distrib/common/elfrdsetroot.c index 011995843ed..506d984f22f 100644 --- a/distrib/common/elfrdsetroot.c +++ b/distrib/common/elfrdsetroot.c @@ -1,4 +1,4 @@ -/* $OpenBSD: elfrdsetroot.c,v 1.11 2006/10/11 20:56:59 deraadt Exp $ */ +/* $OpenBSD: elfrdsetroot.c,v 1.12 2007/08/02 23:10:05 ray Exp $ */ /* $NetBSD: rdsetroot.c,v 1.2 1995/10/13 16:38:39 gwr Exp $ */ /* @@ -38,6 +38,7 @@ #include <sys/types.h> #include <sys/file.h> #include <sys/mman.h> +#include <sys/stat.h> #include <stdio.h> #include <stdlib.h> @@ -168,6 +169,17 @@ main(int argc, char **argv) exit(1); } } else { + struct stat sstat; + + if (fstat(STDIN_FILENO, &sstat) == -1) { + perror("fstat"); + exit(1); + } + if (S_ISREG(sstat.st_mode) && + sstat.st_size > rd_root_size_val) { + fprintf(stderr, "ramdisk too small\n"); + exit(1); + } n = read(STDIN_FILENO, dataseg + rd_root_image_off, rd_root_size_val); if (n < 0) { diff --git a/distrib/common/rdsetroot.c b/distrib/common/rdsetroot.c index cb5a4250204..ffda157224a 100644 --- a/distrib/common/rdsetroot.c +++ b/distrib/common/rdsetroot.c @@ -1,4 +1,4 @@ -/* $OpenBSD: rdsetroot.c,v 1.9 2005/01/14 22:47:06 deraadt Exp $ */ +/* $OpenBSD: rdsetroot.c,v 1.10 2007/08/02 23:10:05 ray Exp $ */ /* $NetBSD: rdsetroot.c,v 1.2 1995/10/13 16:38:39 gwr Exp $ */ /* @@ -36,8 +36,10 @@ #include <sys/types.h> #include <sys/file.h> #include <sys/mman.h> +#include <sys/stat.h> #include <stdio.h> +#include <stdlib.h> #include <unistd.h> #include <a.out.h> @@ -180,6 +182,17 @@ main(int argc, char *argv[]) exit(1); } } else { + struct stat sstat; + + if (fstat(STDIN_FILENO, &sstat) == -1) { + perror("fstat"); + exit(1); + } + if (S_ISREG(sstat.st_mode) && + sstat.st_size > rd_root_size_val) { + fprintf(stderr, "ramdisk too small\n"); + exit(1); + } n = read(STDIN_FILENO, dataseg + rd_root_image_off, rd_root_size_val); if (n < 0) { |