FreeBSD Bugzilla – Attachment 9556 Details for
Bug 19537
patch to prevent cat'ing directories
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
[patch]
file.diff
file.diff (text/plain), 1.82 KB, created by
kbyanc
on 2000-06-27 02:20:03 UTC
(
hide
)
Description:
file.diff
Filename:
MIME Type:
Creator:
kbyanc
Created:
2000-06-27 02:20:03 UTC
Size:
1.82 KB
patch
obsolete
>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 01:07:13 >@@ -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 (sb->st_mode & S_IFDIR) >+ errx(1, "%s is a directory", fname); >+ if (sb->st_mode & S_IFLNK) >+ /* This should transparently be resolved and >+ * thus never happen. >+ */ >+ errx(1, "%s is a symlink", fname); >+ if (sb->st_mode & S_IFWHT) >+ /* This should never happen. */ >+ errx(1, "%s is a whiteout entry", fname); > }
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 19537
: 9556