xditview '.' hangs

Philipp Hagemeister phihag at phihag.de
Mon Dec 6 10:36:58 PST 2010


You've just introduced a race condition: What if I delete the file just
after you called fstat and create a regular file in its place? Use fstat
instead of stat.

Regards,

Philipp

Pat Kane wrote:
> Attached is a patch to try.
> 
> Pat
> ---
> 
> [PATCH xditview] Make sure filename is a regular file.
> 
> If filename is not '-' or '|' make sure it is a regular file.
> 
> Signed-off-by: Patrick E. Kane <pekane52 at gmail.com>
> 
> ---
>  xditview.c |   14 ++++++++++++++
>  1 files changed, 14 insertions(+), 0 deletions(-)
> 
> diff --git a/xditview.c b/xditview.c
> index 99fd240..dbb183b 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,6 +396,19 @@ VisitFile (char *name, Boolean resetPage)
>      else if (name[0] == '|')
>         new_file = popen (name+1, "r");
>      else {
> +         struct stat stbuf;
> +         /*
> +          * Make sure it is a regular file
> +          */
> +         if (stat(name, &stbuf) != 0) {
> +             perror(name);
> +             return;
> +         }
> +         if (! S_ISREG(stbuf.st_mode)){
> +             fprintf(stderr, "%s is not a regular file\n", name);
> +             return;
> +         }
> +
>         new_file = fopen (name, "r");
>         seek = 1;
>      }
> 
> 
> ------------------------------------------------------------------------
> 
> _______________________________________________
> xorg at lists.freedesktop.org: X.Org support
> Archives: http://lists.freedesktop.org/archives/xorg
> Info: http://lists.freedesktop.org/mailman/listinfo/xorg
> Your subscription address: phihag at phihag.de



-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 197 bytes
Desc: OpenPGP digital signature
URL: <http://lists.x.org/archives/xorg/attachments/20101206/2f26382e/attachment.pgp>


More information about the xorg mailing list