This is the second version of patch.

It now uses fstat instead of stat as recommended in
review comments from:
    Philipp Hagemeister <[email protected]>.
Bug was reported by:
    Krzysztof Żelechowski <[email protected]>

Signed-off-by: Pat Kane <[email protected]>

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
[PATCH xditview] make sure filename is a regular file.

This is the second version of the patch.  It now uses
fstat instead of stat as recommended in review comments
from Philipp Hagemeister <[email protected]>.

Signed-off-by: Pat Kane <[email protected]>
---
 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

_______________________________________________
[email protected]: X.Org development
Archives: http://lists.x.org/archives/xorg-devel
Info: http://lists.x.org/mailman/listinfo/xorg-devel

Reply via email to