tar: do not dereference NULL pointer with '--remove-files .'

Problem reported by Thorsten Hirsch in:
http://lists.gnu.org/archive/html/bug-tar/2014-04/msg00011.html
* src/unlink.c (flush_deferred_unlinks):
Do not attempt to find the parent of "." when "." is
at the top level.
* tests/remfiles10.at: New file.
* tests/Makefile.am (TESTSUITE_AT):
* tests/testsuite.at: Add it.
This commit is contained in:
Paul Eggert
2014-04-29 14:22:59 -07:00
parent 7808b6981b
commit fc58a8bd98
4 changed files with 53 additions and 4 deletions
+5 -4
View File
@@ -73,7 +73,7 @@ flush_deferred_unlinks (bool force)
{
struct deferred_unlink *p, *prev = NULL;
int saved_chdir = chdir_current;
for (p = dunlink_head; p; )
{
struct deferred_unlink *next = p->next;
@@ -86,15 +86,16 @@ flush_deferred_unlinks (bool force)
{
const char *fname;
if (p->file_name[0] == 0 ||
strcmp (p->file_name, ".") == 0)
if (p->dir_idx
&& (p->file_name[0] == 0
|| strcmp (p->file_name, ".") == 0))
{
fname = tar_dirname ();
chdir_do (p->dir_idx - 1);
}
else
fname = p->file_name;
if (unlinkat (chdir_fd, fname, AT_REMOVEDIR) != 0)
{
switch (errno)