Project

General

Profile

Actions

Bug #3736

open

cp -r shouldn't allow infinite loops

Added by Rich Lowe about 10 years ago. Updated over 9 years ago.

Status:
In Progress
Priority:
Normal
Assignee:
-
Category:
-
Start date:
2013-04-19
Due date:
% Done:

60%

Estimated time:
Difficulty:
Medium
Tags:
needs-triage
Gerrit CR:
External Bug:

Description

If you do

> mkdir foo
> cp -r . foo

cp will loop ever deeper, until you run out of file descriptors (which may indicate it's leaking them, I haven't checked if that's to be expected or not).

It should stop short, as GNU cp does (but BSD cp doesn't, that one runs out to PATH_MAX instead).


Files

diff (955 Bytes) diff Alexander Eremin, 2013-05-13 04:29 PM
Actions #1

Updated by Garrick Peterson about 10 years ago

I've started taking a look at this. Don't have permissions to assign bug to myself, but will update with progress.

[edit 2013-05-10]
The initial bug is fixed and working. If ( source == target ) it skips to the next item. The remainder of the current directory is still recursively-copied to foo/ as expected. Also a warning is printed to stdout.

However this still fails. Not yet sure how to fix this.


$ mkdir -p foo/bar 
$ cp -r . foo/bar/ 

Also trying to refactor the relevant function and clean up the code a bit. Doing that in a separate git branch for now.

Actions #2

Updated by Alexander Eremin about 10 years ago

Possible fix is attached

Actions #3

Updated by Garrick Peterson about 10 years ago

  • Status changed from New to In Progress
  • % Done changed from 0 to 60

Going to publish webrev shortly for initial review. Will need a strategy/tool for thorough testing.

Took a different approach from Alexander. Now that mine is working, I'm comparing them more closely. Also did some refactoring in the same function, where it made sense.

Actions #4

Updated by Alexander Eremin over 9 years ago

Any updates?

Actions

Also available in: Atom PDF