Bug 222089 - Double free in fts_close()
Double free in fts_close()
Status: CLOSED RAWHIDE
Product: Fedora
Classification: Fedora
Component: glibc (Show other bugs)
rawhide
All Linux
medium Severity medium
: ---
: ---
Assigned To: Jakub Jelinek
Brian Brock
:
Depends On:
Blocks:
  Show dependency treegraph
 
Reported: 2007-01-10 02:26 EST by Miloslav Trmač
Modified: 2007-11-30 17:11 EST (History)
2 users (show)

See Also:
Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Environment:
Last Closed: 2007-01-18 16:40:17 EST
Type: ---
Regression: ---
Mount Type: ---
Documentation: ---
CRM:
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---


Attachments (Terms of Use)
Make sure fts_cur is always valid after return from fts_read () (950 bytes, patch)
2007-01-10 02:26 EST, Miloslav Trmač
no flags Details | Diff

  None (edit)
Description Miloslav Trmač 2007-01-10 02:26:57 EST
Description of problem:
fts_read () may free () sp->fts_cur without updating sp->fts_cur to point to
another fts_ent, causing a double free in fts_close ().  This can happen only if
fchdir () or fts_safe_changedir () fails, which is why it usually doesn't happen
in practice.

The attached patch should fix the bug;  the unhandled exits from fts_read ()
were the error exits setting FTS_STOP, except for the first such exit.

Version-Release number of selected component (if applicable):
glibc-2.5.90-14

How reproducible:
Easiest by manually editing the code to fail in fts_safe_changedir () or
the FCHDIR calls.
Comment 1 Miloslav Trmač 2007-01-10 02:26:57 EST
Created attachment 145235 [details]
Make sure fts_cur is always valid after return from fts_read ()
Comment 2 Jim Meyering 2007-01-10 05:56:00 EST
Thanks for the report and fine patch.
FYI, this is fixed in what I consider to be "upstream": coreutils,
and now gnulib.  I fixed that same bug a year ago today:

    http://git.sv.gnu.org/gitweb/?p=coreutils.git;a=commit;h=58e925ce5fa

That one-line addition is a subset of your patch.
FYI, now, the master copy of fts.c is in gnulib.
I agree with the other parts of your change, too.  Those hunks appear
to be solely for improved maintainability -- a very good thing,
in fts.c!  It might be nice to put them in a separate delta.
I'm about to apply them to the gnulib version of fts.c.

For those who don't yet know, I should qualify the "upstream"
comment.  glibc is constrained by its ABI, and that is precisely
the problem, e.g., limiting the length of a full name to fit in
a short.  Also the O(depth^2) cycle-detection behavior that is
apparent for very deep trees.  Both of those are fixed in the gnulib
version, but making the changes in the glibc version would break
ABI compatibility.  Eventually, I will rename symbols in gnulib's
fts.c, and propose the addition of "nfts" to glibc.
Comment 3 Ulrich Drepper 2007-01-10 13:39:00 EST
Applied upstream.
Comment 4 Jakub Jelinek 2007-01-18 16:40:17 EST
Should be fixed in glibc-2.5.90-15 in rawhide.

Note You need to log in before you can comment on or make changes to this bug.