bug-textutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

textutils 2.0 sort bug: deletes incorrect /tmp files


From: Ketil Froyn
Subject: textutils 2.0 sort bug: deletes incorrect /tmp files
Date: Wed, 16 May 2001 18:27:52 +0200 (CEST)

Hi.

I have found a bug in sort. The bug is that if sort encounters a file
that already exists in the xtmpfopen() function, open() fails (because of
the O_EXCL flag). When cleanup() is called now, sort will wrongfully
delete the file that it encountered. I would like to propose this patch:

diff -urN ../textutils-2.0/src/sort.c ./src/sort.c

--- ../textutils-2.0/src/sort.c Thu Aug  5 09:42:49 1999
+++ ./src/sort.c        Wed May 16 17:52:17 2001
@@ -327,6 +327,7 @@
 {
   FILE *fp;
   int fd;
+  struct tempnode *node;

   /*  Open temporary file exclusively, to foil a common
       denial-of-service attack.  */
@@ -334,6 +335,10 @@
   if (fd < 0 || (fp = fdopen (fd, "w")) == NULL)
     {
       error (0, errno, "%s", file);
+      node = temphead.next;
+      temphead.next = node->next;
+      free(node->text);
+      free(node);
       cleanup ();
       exit (SORT_FAILURE);
     }


Also, it doesn't really need to be a fatal error if a file can't be
opened, does it?

Ketil Froyn








reply via email to

[Prev in Thread] Current Thread [Next in Thread]