[PATCH xditview] make sure filename is a regular file.
Pat Kane
pekane52 at gmail.com
Tue Dec 7 20:32:24 PST 2010
This is the second version of patch.
It now uses fstat instead of stat as recommended in
review comments from:
Philipp Hagemeister <phihag at phihag.de>.
Bug was reported by:
Krzysztof Żelechowski <giecrilj at stegny.2a.pl>
Signed-off-by: Pat Kane <pekane52 at gmail.com>
P.S. also attached, in case gmail munges the whitespace...
---
xditview.c | 18 ++++++++++++++++++
1 files changed, 18 insertions(+), 0 deletions(-)
diff --git a/xditview.c b/xditview.c
index 99fd240..facb361 100644
--- a/xditview.c
+++ b/xditview.c
@@ -59,6 +59,7 @@ from the X Consortium.
#include "xdit_mask.bm"
#include <stdio.h>
#include <stdlib.h>
+#include <sys/stat.h>
/* Command line options table. Only resources are entered here...there is a
pass over the remaining options after XtParseCommand is let loose. */
@@ -395,7 +396,24 @@ VisitFile (char *name, Boolean resetPage)
else if (name[0] == '|')
new_file = popen (name+1, "r");
else {
+ struct stat stbuf;
+
new_file = fopen (name, "r");
+
+ if (!new_file) {
+ perror(name);
+ return;
+ }
+ /* Make sure it is a regular file */
+ if (fstat(fileno(new_file), &stbuf) != 0) {
+ perror(name);
+ return;
+ }
+ if (! S_ISREG(stbuf.st_mode)){
+ fprintf(stderr, "%s is not a regular file.\n", name);
+ return;
+ }
+
seek = 1;
}
if (!new_file) {
--
1.7.1
-------------- next part --------------
A non-text attachment was scrubbed...
Name: regular-file.patch
Type: text/x-patch
Size: 1374 bytes
Desc: not available
URL: <http://lists.x.org/archives/xorg-devel/attachments/20101207/d396f6d3/attachment-0001.bin>
More information about the xorg-devel
mailing list