bugfindutils - Bugs: bug #39162, -printf option reads beyond...


bug #39162: -printf option reads beyond arguments terminated by \

Submitted by:  None
Submitted on:  Tue 04 Jun 2013 03:23:28 PM UTC  
Category: findSeverity: 2 - Minor
Item Group: NoneStatus: Fixed
Privacy: PublicAssigned to: James Youngman <jay>
Originator Name: Paul MarinescuOriginator Email: -unavailable-
Open/Closed: ClosedRelease: 4.5.9
Fixed Release: 4.5.12

Add a New Comment(Rich Markup)

You are not logged in

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


Mon 23 Sep 2013 11:29:12 PM UTC, comment #3:

Fixed by this change:


James Youngman <jay>
Project AdministratorIn charge of this item.
Wed 05 Jun 2013 02:11:58 AM UTC, comment #2:

Yes, I meant one of the commands that you listed. I don't have a run which shows the problem and I'm not sure whether that can be produced on an x64 box because of the stack layout, but I could imagine a memory violation happening on other architectures.

However, you can easily see the issue by adding a print statement inside the for loop from insert_fprintf. This will print not only the -printf argument but also part of envp (which follows on stack). Using the same command line, a change like

--- a/find/print.c
+++ b/find/print.c
@@ -329,6 +329,7 @@ insert_fprintf (struct format_val *vec,

for (fmt_editpos = segstart; *fmt_editpos; fmt_editpos++)
+ printf("%c", *fmt_editpos);
if (fmt_editpos[0] == '\\' && fmt_editpos[1] == 'c')
make_segment (segmentp, segstart, fmt_editpos - segstart,


%\find/find: warning: unrecognized escape `\'

TERM=xterm-256color should not be there.

Tue 04 Jun 2013 04:44:37 PM UTC, comment #1:

Did you mean one of:
find . -printf '%f\'
find . -printf "%f\\"
because in shell, "%f\" is an unterminated quote, and you wouldn't have invoked find in the first place.
Do you have instructions for detecting the problem, such as a valgrind run that proves that we were accessing uninitialized memory?

Eric Blake <ericb>
Project Administrator
Tue 04 Jun 2013 03:23:28 PM UTC, original submission:

When parsing a -printf argument, insert_fprintf treats a lone \ incorrectly when it's the last character of the argument, reading beyond the terminating NUL, e.g.

find . -printf "%f\"

This is hard to notice because the final make_segment call does take the terminating NUL into account.



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

Attach File(s):

Attached Files
file #28291:  findutils39162.patch added by None (498B - application/octet-stream - possible patch)


Depends on the following items: None found

Items that depend on this one: None found


Carbon-Copy List
  • -unavailable- added by jay (Posted a comment)
  • -unavailable- added by ericb (Posted a comment)
  • -unavailable- added by None (Submitted the item)

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

    Only logged-in users can vote.


    Please enter the title of George Orwell's famous dystopian book (it's a date):



    Follow 9 latest changes.

    Date Changed By Updated Field Previous Value => Replaced By
    Tue 24 Sep 2013 10:04:45 PM UTCjayOpen/ClosedOpen=>Closed
      Fixed ReleaseNone=>4.5.12
      Summary-printf option reads beyond arguments terminated by \\=>-printf option reads beyond arguments terminated by \
    Mon 23 Sep 2013 11:29:12 PM UTCjaySeverity3 - Normal=>2 - Minor
      Assigned toNone=>jay
      Summary-printf option reads beyond arguments terminated by \\=>-printf option reads beyond arguments terminated by \
    Tue 11 Jun 2013 12:28:39 PM UTCNoneAttached File-=>Added findutils39162.patch, #28291
    Tue 04 Jun 2013 04:44:37 PM UTCericbSummary-printf option reads beyond arguments terminated by \\=>-printf option reads beyond arguments terminated by \

    Back to the top

    Powered by Savane 3.1-cleanup1