[PATCH xditview] make sure filename is a regular file.

Alan Coopersmith alan.coopersmith at oracle.com
Sun May 6 02:09:59 UTC 2018


Sorry for letting this get lost in our massive backlog, but it seemed to work
well a quick test with /dev/null so I've pushed it to git master now:

To ssh://git.freedesktop.org/git/xorg/app/xditview
   5383f40..3cd0b7e  master -> master

Thanks for the patch!

	-alan-

On 12/ 7/10 08:32 PM, Pat Kane wrote:
> 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) {
> 
> 
> 
> _______________________________________________
> xorg-devel at lists.x.org: X.Org development
> Archives: http://lists.x.org/archives/xorg-devel
> Info: http://lists.x.org/mailman/listinfo/xorg-devel
> 


-- 
	-Alan Coopersmith-               alan.coopersmith at oracle.com
	 Oracle Solaris Engineering - https://blogs.oracle.com/alanc


More information about the xorg-devel mailing list