From c17bf5b6e09630b6a15bbb88599bc2cc3769c300 Mon Sep 17 00:00:00 2001 From: Serge ??? Date: Sun, 15 Sep 1985 23:55:14 -0800 Subject: [PATCH] disallow "Mail -f directory" (or other non-plain file) SCCS-vsn: usr.bin/mail/lex.c 5.3 --- usr/src/usr.bin/mail/lex.c | 35 +++++++++++++++++++++++++++-------- 1 file changed, 27 insertions(+), 8 deletions(-) diff --git a/usr/src/usr.bin/mail/lex.c b/usr/src/usr.bin/mail/lex.c index 94fcf029de..2a0f20b8c6 100644 --- a/usr/src/usr.bin/mail/lex.c +++ b/usr/src/usr.bin/mail/lex.c @@ -5,11 +5,12 @@ */ #ifndef lint -static char *sccsid = "@(#)lex.c 5.2 (Berkeley) %G%"; +static char *sccsid = "@(#)lex.c 5.3 (Berkeley) %G%"; #endif not lint #include "rcv.h" #include +#include /* * Mail -- a mail program @@ -35,16 +36,34 @@ setfile(name, isedit) static int shudclob; static char efile[128]; extern char tempMesg[]; + extern int errno; if ((ibuf = fopen(name, "r")) == NULL) return(-1); - if (!edit) { - if (fstat(fileno(ibuf), &stb) < 0) { - perror(name); - exit(1); - } - if (stb.st_size == 0) - return(-1); + + if (fstat(fileno(ibuf), &stb) < 0) { + fclose(ibuf); + return (-1); + } + + switch (stb.st_mode & S_IFMT) { + case S_IFDIR: + fclose(ibuf); + errno = EISDIR; + return (-1); + + case S_IFREG: + break; + + default: + fclose(ibuf); + errno = EINVAL; + return (-1); + } + + if (!edit && stb.st_size == 0) { + fclose(ibuf); + return(-1); } /* -- 2.20.1