Date: Mon, 26 Jun 2000 22:40:03 -0700 (PDT) From: Kelly Yancey <kbyanc@posi.net> To: freebsd-bugs@FreeBSD.org Subject: Re: bin/19537: patch to prevent cat'ing directories Message-ID: <200006270540.WAA84094@freefall.freebsd.org>
next in thread | raw e-mail | index | archive | help
The following reply was made to PR bin/19537; it has been noted by GNATS.
From: Kelly Yancey <kbyanc@posi.net>
To: freebsd-gnats-submit@FreeBSD.org
Cc:
Subject: Re: bin/19537: patch to prevent cat'ing directories
Date: Mon, 26 Jun 2000 22:32:59 -0700 (PDT)
Actually, the following is a more correct patch, please apply it instead.
Kelly
Index: bin/cat/cat.c
===================================================================
RCS file: /home/cvs/src/bin/cat/cat.c,v
retrieving revision 1.15
diff -u -r1.15 cat.c
--- bin/cat/cat.c 2000/04/14 21:01:35 1.15
+++ bin/cat/cat.c 2000/06/27 05:24:39
@@ -68,6 +68,7 @@
int main __P((int argc, char *argv[]));
void raw_args __P((char *argv[]));
void raw_cat __P((int));
+void checkmode __P((struct stat *, char *));
int
main(argc, argv)
@@ -121,6 +122,7 @@
cook_args(argv)
char **argv;
{
+ struct stat sb;
register FILE *fp;
fp = stdin;
@@ -129,12 +131,14 @@
if (*argv) {
if (!strcmp(*argv, "-"))
fp = stdin;
- else if ((fp = fopen(*argv, "r")) == NULL) {
+ else if ((fp = fopen(*argv, "r")) == NULL ||
+ fstat(fileno(fp), &sb)) {
warn("%s", *argv);
rval = 1;
++argv;
continue;
}
+ checkmode(&sb, *argv);
filename = *argv++;
}
cook_buf(fp);
@@ -211,6 +215,7 @@
raw_args(argv)
char **argv;
{
+ struct stat sb;
register int fd;
fd = fileno(stdin);
@@ -219,12 +224,14 @@
if (*argv) {
if (!strcmp(*argv, "-"))
fd = fileno(stdin);
- else if ((fd = open(*argv, O_RDONLY, 0)) < 0) {
+ else if ((fd = open(*argv, O_RDONLY, 0)) < 0 ||
+ fstat(fd, &sb)) {
warn("%s", *argv);
rval = 1;
++argv;
continue;
}
+ checkmode(&sb, *argv);
filename = *argv++;
}
raw_cat(fd);
@@ -259,4 +266,21 @@
warn("%s", filename);
rval = 1;
}
+}
+
+void
+checkmode(sb, fname)
+ struct stat *sb;
+ char *fname;
+{
+ if (S_ISDIR(sb->st_mode))
+ errx(1, "%s is a directory", fname);
+ if (S_ISLNK(sb->st_mode))
+ /* This should be transparently resolved and
+ * thus never happen.
+ */
+ errx(1, "%s is a symlink", fname);
+ if (S_ISWHT(sb->st_mode))
+ /* This should never happen. */
+ errx(1, "%s is a whiteout entry", fname);
}
To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-bugs" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200006270540.WAA84094>
