bug-coreutils
[Top][All Lists]
Advanced

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

bug#7305: sort command not working in version 5.5 as it did in 4.7


From: Paul Eggert
Subject: bug#7305: sort command not working in version 5.5 as it did in 4.7
Date: Wed, 17 Nov 2010 20:03:34 -0800
User-agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.12) Gecko/20101027 Thunderbird/3.1.6

On 11/17/2010 05:41 PM, Pádraig Brady wrote:

> Yes that is marginally safer but less useful in the common
> case of using an isolated +...
> 
> $ sort --debug +1
> sort: using `en_US.utf8' sorting rules
> sort: non-portable file name +1; use ./+1 instead
> sort: open failed: +1: No such file or directory

Is the issue here that the two error messages are confusing, and
that there should be just one?  If so, that's easy to fix by adding
a call to 'access', as follows.  Normally I'd use euidaccess but
that would introduce more dependencies than this issue is worth.
(PS. This patch spells it "nonportable", for consistency with
pathchk.)

diff --git a/src/sort.c b/src/sort.c
index 7e25f6a..1ad7386 100644
--- a/src/sort.c
+++ b/src/sort.c
@@ -3990,6 +3990,7 @@ main (int argc, char **argv)
   bool need_random = false;
   unsigned long int nthreads = 0;
   size_t nfiles = 0;
+  size_t unprotected_file_names = 0;
   bool posixly_correct = (getenv ("POSIXLY_CORRECT") != NULL);
   bool obsolete_usage = (posix2_version () < 200112);
   char **files;
@@ -4113,6 +4114,7 @@ main (int argc, char **argv)
           if (argc <= optind)
             break;
           files[nfiles++] = argv[optind++];
+          unprotected_file_names += (c != -1);
         }
       else switch (c)
         {
@@ -4165,7 +4167,10 @@ main (int argc, char **argv)
                 }
             }
           if (! key)
-            files[nfiles++] = optarg;
+            {
+              files[nfiles++] = optarg;
+              unprotected_file_names++;
+            }
           break;
 
         case SORT_OPTION:
@@ -4470,6 +4475,15 @@ main (int argc, char **argv)
                quote (setlocale (LC_COLLATE, NULL)));
       else
         error (0, 0, _("using simple byte comparison"));
+
+      for (size_t i = 0; i < unprotected_file_names; i++)
+        if (files[i][0] == '+' && access (files[i], R_OK) == 0)
+          {
+            char const *q = quotearg_style (shell_quoting_style, files[i]);
+            error (0, 0, _("nonportable file name %s; use ./%s instead"),
+                   q, q);
+          }
+
       key_warnings (&gkey, gkey_only);
     }
 





reply via email to

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