Sorry for the mixup, corrected:
You've just introduced a race condition: What if I delete the file just
after you called *stat* and create a *directory* 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 <pekan...@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@lists.freedesktop.org: X.Org support
>> Archives: http://lists.freedesktop.org/archives/xorg
>> Info: http://lists.freedesktop.org/mailman/listinfo/xorg
>> Your subscription address: phi...@phihag.de
> 
> 
> 
> 
> ------------------------------------------------------------------------
> 
> _______________________________________________
> xorg@lists.freedesktop.org: X.Org support
> Archives: http://lists.freedesktop.org/archives/xorg
> Info: http://lists.freedesktop.org/mailman/listinfo/xorg
> Your subscription address: phi...@phihag.de

Attachment: signature.asc
Description: OpenPGP digital signature

_______________________________________________
xorg@lists.freedesktop.org: X.Org support
Archives: http://lists.freedesktop.org/archives/xorg
Info: http://lists.freedesktop.org/mailman/listinfo/xorg
Your subscription address: arch...@mail-archive.com

Reply via email to