bugfindutils - Bugs: bug #66365, find -exec treats + as special...

 
 

bug #66365: find -exec treats + as special when it shouldn't

Submitter:  Geoff Clare <geoffclare>
Submitted:  Tue 22 Oct 2024 10:43:11 AM UTC
   
 
Category:  None Severity:  4 - Important
Item Group:  None Status:  None
Privacy:  Public Assigned to:  jay
Originator Name:  Open/Closed:  Open
Release:  4.2.12 Fixed Release:  None
* Mandatory Fields

Add a New Comment Rich Markup
   

Thu 31 Oct 2024 04:27:01 PM UTC, comment #4: 

I think the attached patch should fix this.

(file #56587)

James Youngman <jay>
Group administrator
Thu 31 Oct 2024 01:14:28 PM UTC, comment #3: 

This bug was introduced in findutils 4.2.12, which is the release which added support for "+".  Before that, the bug as stated isn't reproducible since "+" is not considered to be a terminator for -exec at all.

Essentially though, all previous releases are faulty, either by not supporting "+" or by supporting it but with this bug.

James Youngman <jay>
Group administrator
Thu 31 Oct 2024 12:57:40 PM UTC, comment #2: 

Because GNU find currently rejects these commands with the error shown in Geoff's comment, I'm not expecting there to be a substantial problem with backward incompatibility.  That is, I doubt that anybody is likely to be relying on GNU find rejecting commands like


find . -prune -exec echo x{} + \;



The standard says:

>  If more than one argument containing the two characters "{}" is present, the behavior is unspecified.


The GNU find manual page states that multiple "{}" is not allowed (and indeed, this is rejected).  I believe that his aspect of the current behaviour should remain unchanged.


James Youngman <jay>
Group administrator
Thu 31 Oct 2024 12:49:39 PM UTC, comment #1: 

Implicit in Geoff's comment is that the rules for terminating the expression are different for the ";" and "+" cases.   The full wording from the standard (IEEE Std 1003.1-2024) is:

-exec utility_name [argument ...] ;
-exec utility_name [argument ...]  {} +

The end of the primary expression shall be punctuated by a <semicolon> or by a <plus-sign>. Only a <plus-sign> that immediately follows an argument containing only the two characters "{}" shall punctuate the end of the primary expression. Other uses of the <plus-sign> shall not be treated as special.
If the primary expression is punctuated by a <semicolon>, the utility utility_name shall be invoked once for each pathname and the primary shall evaluate as true if the utility returns a zero value as exit status. A utility_name or argument containing only the two characters "{}" shall be replaced by the current pathname. If a utility_name or argument string contains the two characters "{}", but not just the two characters "{}", it is implementation-defined whether find replaces those two characters or uses the string without change.

If the primary expression is punctuated by a <plus-sign>, the primary shall always evaluate as true, and the pathnames for which the primary is evaluated shall be aggregated into sets. The utility utility_name shall be invoked once for each set of aggregated pathnames. Each invocation shall begin after the last pathname in the set is aggregated, and shall be completed before the find utility exits and before the first pathname in the next set (if any) is aggregated for this primary, but it is otherwise unspecified whether the invocation occurs before, during, or after the evaluations of other primaries. If any invocation returns a non-zero value as exit status, the find utility shall return a non-zero exit status. An argument containing only the two characters "{}" shall be replaced by the set of aggregated pathnames, with each pathname passed as a separate argument to the invoked utility in the same order that it was aggregated. The size of any set of two or more pathnames shall be limited such that execution of the utility does not cause the system's {ARG_MAX} limit to be exceeded. If more than one argument containing the two characters "{}" is present, the behavior is unspecified.

The current directory for the invocation of utility_name shall be the same as the current directory when the find utility was started. If the utility_name names any of the special built-in utilities (see 2.15 Special Built-In Utilities ), the results are undefined.

James Youngman <jay>
Group administrator
Tue 22 Oct 2024 10:43:11 AM UTC, original submission:  

POSIX requires that a "+" supplied to "-exec" is only treated as special when it follows an argument that is exactly "{}".

So in the command:

find . -prune -exec echo x{} + \;

the "+" is not special and the command should output "x. +", but GNU find treats it as special:

$ find . -prune -exec echo x{} + \;        
find: In ‘-exec ... {} +’ the ‘{}’ must appear by itself, but you specified ‘x{}’

Tested with findutils 4.9.0 as included in Debian bookworm.

Here's the relevant text from POSIX.1-2024 (it was the same in .1-2008):

"Only a <plus-sign> that immediately follows an argument containing only the two characters "{}" shall punctuate the end of the primary expression. Other uses of the <plus-sign> shall not be treated as special."

Geoff Clare <geoffclare>

 

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

Attach Files:
   
   
Comment:
   

Attached Files

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by jay (Updated the item)
  • -email is unavailable- added by geoffclare (Submitted the item)
  •  

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

    Only logged-in users can vote.

     

    Follow 4 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2024-10-31 jay Attached File- Added 0001-find-Fix-Savannah-bug-66365.patch, #56587
    2024-10-31 jay ReleaseNone 4.2.12
    2024-10-31 jay Severity3 - Normal 4 - Important
        Assigned toNone jay

    Back to the top

    Powered by Savane 3.14-3b9d.
    Corresponding source code