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:  find Severity:  2 - Minor
Item Group:  None Status:  Fixed
Privacy:  Public Assigned to:  James Youngman <jay>
Originator Name:  Paul Marinescu Originator Email:  -email is unavailable-
Open/Closed:  Closed Release:  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:

http://git.savannah.gnu.org/cgit/findutils.git/commit/?id=cdd390b492d7e9db18a1e9aa88e42525ce4022e5

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,

prints

%\find/find: warning: unrecognized escape `\'
TERM=xterm-256color
...

TERM=xterm-256color should not be there.

Anonymous
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.

Anonymous

 

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

Attach Files:
   
   
Comment:
   

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
  • -email is unavailable- added by jay (Posted a comment)
  • -email is unavailable- added by ericb (Posted a comment)
  • -email is unavailable- added by None (Submitted the item)
  •  

    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 9 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2013-09-24 jay Open/ClosedOpen => Closed
        Fixed ReleaseNone => 4.5.12
        Summary-printf option reads beyond arguments terminated by \\ => -printf option reads beyond arguments terminated by \
    2013-09-23 jay Severity3 - Normal => 2 - Minor
        StatusNone => Fixed
        Assigned toNone => jay
        Summary-printf option reads beyond arguments terminated by \\ => -printf option reads beyond arguments terminated by \
    2013-06-11 None Attached File- => Added findutils39162.patch, #28291
    2013-06-04 ericb Summary-printf option reads beyond arguments terminated by \\ => -printf option reads beyond arguments terminated by \

    Back to the top


    Powered by Savane 3.3