bugfindutils - Bugs: bug #15235, Leading directories are misparsed...


bug #15235: Leading directories are misparsed as expressions

Submitted by:  Eric Blake <ericb>
Submitted on:  Sun 18 Dec 2005 04:59:07 AM UTC  
Category:  find Severity:  3 - Normal
Item Group:  Wrong result Status:  Fixed
Privacy:  Public Assigned to:  James Youngman <jay>
Originator Name:  Eric Blake Open/Closed:  Closed
Release:  4.2.27 Fixed Release:  4.3.1

Add a New Comment (Rich Markup)

You are not logged in

Please log in, so followups can be emailed to you.


( Jump to the original submission)

Mon 07 Aug 2006 09:43:52 AM UTC, comment #8: 

Fixed in 4.3.1, which is now released

James Youngman <jay>
Project AdministratorIn charge of this item.
Tue 20 Dec 2005 06:52:06 PM UTC, comment #7: 

I've fixed the additional problems and applied the documentation parts of your patch.   I edited the ChangeLog entry slightly before  prepending it.

Tue 20 Dec 2005 02:06:49 PM UTC, comment #6: 

Also, your patch did not update find.1 or find.texi, so at least part of my patch is still valid.

Eric Blake <ericb>
Project Administrator
Tue 20 Dec 2005 01:14:16 PM UTC, comment #5: 

Your patch is not quite right:

+looks_like_expression(const char *arg)
+  switch (arg[0])
+    {
+    case '-':
+      if (arg[1])              /* "-foo" is an expression.  */
+       return true;
+      else
+       return false;           /* Just "-" is a filename. */
+      break;

Hmm, I thought that "-" starts with a '-', so it should be treated as an invalid option, but I guess you are okay in saying that the POSIX wording of "starts with" implies improper substring, therefore "-" is a filename since it is an exact match rather than a prefix.

Which raises the question - if you treat "-" as a filename, is it the file ./-, or is it shorthand for stdin (on systems where stdin can be redirected from a directory)?

+      /* According to the POSIX standard, we have to assume that a leading ')'
is a
+       * filename argument.   Hence it does not matter if the ')' is followed b
y any
+       * other characters.
+       */
+    case ')':
+      return false;
+      /* (, ) and ! are part of an expression,
+       * but (2, )3 and !foo are filenames.
+       */
+    case '!':
+    case '(':
+    case ',':

Wrong - you need to treat ',' like you did ')'; a leading comma is always treated as a filename before the first expression is found.

+      if (arg[1])
+       return false;
+      else
+       return true;
+    default:
+      return false;

Why not combine the code for case ')': (and as I pointed out, case ',':), with default:?

+    }

Thanks for working on this.

Eric Blake <ericb>
Project Administrator
Tue 20 Dec 2005 06:53:44 AM UTC, comment #4: 

Fixed in 4.3.1+, but not in 4.2.x.

James Youngman <jay>
Project AdministratorIn charge of this item.
Mon 19 Dec 2005 02:06:21 PM UTC, comment #3: 

I noticed the patch in comment 2 has the following (in my opinion good) side effect on the failure message emitted for using the empty string:

$ find-4.2.27 ''
find-4.2.27: invalid predicate `'
$ find ''
find: : No such file or directory

This also means that on non-POSIX platforms, where '' is a synonym for '.' rather than an invalid name, patched find '' will search the current directory.  This is the approach taken by coreutils, of deferring the decision of whether '' is valid to the OS rather than rejecting it outright.

Eric Blake <ericb>
Project Administrator
Mon 19 Dec 2005 01:51:38 PM UTC, comment #2: 

Patch attached:

2005-12-19  Eric Blake  <ebb9@byu.net>

  • find/testsuite/find.posix/sv-bug-15235.xo: New file.
  • find/testsuite/find.posix/sv-bug-15235.exp: New file.
  • find/testsuite/Makefile.am (EXTRA_DIST_EXP, EXTRA_DIST_XO): Run

new test to catch savannah bug 15235.

  • find/find.c (main): Follow POSIX rules about first expression


  • NEWS: Document bug fix.
  • find/find.1: Likewise.
  • doc/find.texi (Invoking find): Likewise.
Eric Blake <ericb>
Project Administrator
Sun 18 Dec 2005 05:01:57 AM UTC, comment #1: 

Likewise for:

$ mkdir ,
$ touch ,/d

Buggy behavior:
$ find ,
find: invalid expression; you have used a binary operator with nothing before it.

Expected behavior:
$ find ,

Eric Blake <ericb>
Project Administrator
Sun 18 Dec 2005 04:59:07 AM UTC, original submission:  

Per POSIX, http://www.opengroup.org/onlinepubs/009695399/utilities/find.html, "The first argument that starts with a '-', or is a '!' or a '(', and all subsequent arguments shall be interpreted as an expression made up of the following primaries and operators."

Therefore, the following invocations must treat their argument as a directory name, rather than an expression (or portion thereof).

$ mkdir \(1 \!2 \)
$ touch \(1/a \!2/b \)/c

Buggy behavior:
$ find \)
find: invalid expression: you have too many ')'
$ find \!1
find: invalid predicate `!1'
$ find \(2
find: invalid predicate `(2'

Expected behavior:
$ find \(1 \!2 \)

As a side note, the errors are inconsistent in their use of '' vs. `' quoting.

Eric Blake <ericb>
Project Administrator


(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach Files:

Attached Files
file #2427:  findutils.patch1 added by ericb (5KiB - application/octet-stream - Patch mentioned in comment 2)


Depends on the following items: None found

Items that depend on this one: None found


CC list is empty


Do you think this task is very important?
If so, you can add your encouragement to it.
This task has 0 encouragements so far.

Only logged-in users can vote.




Follow 5 latest changes.

Date Changed by Updated Field Previous Value => Replaced by
2006-08-07 jay Open/ClosedOpen => Closed
    Fixed ReleaseNone => 4.3.1
2005-12-20 jay StatusNone => Fixed
    Assigned toNone => jay
2005-12-19 ericb Attached File- => Added findutils.patch1, #3200

Back to the top

Powered by Savane 3.5