diff options
author | Pat Kane <pekane52@gmail.com> | 2010-12-07 22:32:24 -0600 |
---|---|---|
committer | Alan Coopersmith <alan.coopersmith@oracle.com> | 2018-05-05 19:07:34 -0700 |
commit | 3cd0b7e72ed741bdc26ea7ffd5ea2f4ec3af4f96 (patch) | |
tree | b1d0ebe705ce21f90e261d50df7b1c8a4c2a3400 | |
parent | 5383f408b1138913fd6d7d94da70f63bed711857 (diff) |
make sure filename is a regular file.
This is the second version of patch.
It now uses fstat instead of stat as recommended in
review comments from:
Philipp Hagemeister <phihag@phihag.de>.
Bug was reported by:
Krzysztof Żelechowski <giecrilj@stegny.2a.pl>
Signed-off-by: Pat Kane <pekane52@gmail.com>
Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
-rw-r--r-- | xditview.c | 18 |
1 files changed, 18 insertions, 0 deletions
@@ -57,6 +57,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. */ @@ -324,7 +325,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) { |