xditview '.' hangs

Pat Kane pekane52 at gmail.com
Mon Dec 6 09:00:16 PST 2010


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;
     }
-- 
1.7.1.1


2010/12/6 Krzysztof Żelechowski <giecrilj at stegny.2a.pl>:
> Dnia poniedziałek, 6 grudnia 2010 o 14:47:02 Pat Kane napisał(a):
>> Strace shows that  "xditview ." does:
>>       open(".", O_RDONLY)               = 4
>> followed by an infinite number of:
>>       read(4, 0xb7576000, 4096)         = -1 EISDIR (Is a directory)
>>
>> Looks broken.
>>
>
> Looks like the programmer forgot to examine the return value.  Probably the most common bug in C.
>
> Chris
>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: xditview.patch
Type: text/x-patch
Size: 1204 bytes
Desc: not available
URL: <http://lists.x.org/archives/xorg/attachments/20101206/15ef09c8/attachment.bin>


More information about the xorg mailing list