apt-cache policy silently shows inaccurate information when any file in /etc/apt/sources.list.d is unreadable

Bug #849736 reported by Paul Collins
14
This bug affects 2 people
Affects Status Importance Assigned to Milestone
apt (Ubuntu)
Fix Released
Low
Unassigned

Bug Description

Version: 0.8.16~exp5ubuntu8
Release: 11.10

I've noticed some odd behaviour from apt-cache policy where it pretends, without protest, that package versions in PPAs don't exist.

The trigger seems to be a newly-added source whose .list file I set up to be only readable by root (it contains authentication information).

When any file in /etc/apt/sources.list.d is unreadable, apt-cache won't try to read further files, and it also apparently discards information from any of the files it did manage to read. (Assuming it reads them as it goes — I was only tracing calls to open(2).)

Tags: patch
Paul Collins (pjdc)
summary: apt-cache policy silently shows inaccurate information when any file in
- /etc/apt/sources.list.d are unreadable
+ /etc/apt/sources.list.d is unreadable
Revision history for this message
Torsten Spindler (tspindler) wrote :

Confirmed, sudo is however a workaround:

spindler@spitfire:/etc/apt/sources.list.d$ apt-cache policy apache2
apache2:
  Installed: (none)
  Candidate: 2.2.22-1ubuntu1
  Version table:
     2.2.22-1ubuntu1 0
        500 http://archive.ubuntu.com/ubuntu/ precise/main i386 Packages
spindler@spitfire:/etc/apt/sources.list.d$ sudo apt-cache policy apache2
apache2:
  Installed: (none)
  Candidate: 2.2.22-1ubuntu1
  Version table:
     2.2.22-1ubuntu1 0
        500 http://archive.ubuntu.com/ubuntu/ precise/main i386 Packages
     2.2.14-5ubuntu8 0
        500 http://archive.ubuntu.com/ubuntu/ lucid/main i386 Packages

Changed in apt (Ubuntu):
status: New → Confirmed
Revision history for this message
Torsten Spindler (tspindler) wrote :

Probably this method is not working correctly, it seems to return false whenever a problem with reading and appending a file is encountered (apt-pkg/sourcelist.cc):

// CNC:2003-03-03 - By Anton V. Denisov <email address hidden>.
// SourceList::ReadSourceDir - Read a directory with sources files
// Based on ReadConfigDir() /*{{{*/
// ---------------------------------------------------------------------
/* */
bool pkgSourceList::ReadSourceDir(string Dir)
{
   vector<string> const List = GetListOfFilesInDir(Dir, "list", true);

   // Read the files
   for (vector<string>::const_iterator I = List.begin(); I != List.end(); ++I)
      if (ReadAppend(*I) == false)
         return false;
   return true;

}

Revision history for this message
Torsten Spindler (tspindler) wrote :

The attached patch returns a true from pkgSourceList::ReadAppend when the file is not readable (!F.is_open).

It might be better to change the semantic of ReadAppend to return three values, like ok, fail, fatal. pkgSourceList::ReadSourceDir could then check this return value and either continue (on ok and fail) or abort (fatal). Currently it aborts on any false returned by ReadAppend, causing this bug upon encountering non-readable sources files.

Changed in apt (Ubuntu):
status: Confirmed → Triaged
importance: Undecided → Low
Revision history for this message
Ubuntu Foundations Team Bug Bot (crichton) wrote :

The attachment "apt-unreadable_sources.patch" of this bug report has been identified as being a patch. The ubuntu-reviewers team has been subscribed to the bug report so that they can review the patch. In the event that this is in fact not a patch you can resolve this situation by removing the tag 'patch' from the bug report and editing the attachment so that it is not flagged as a patch. Additionally, if you are member of the ubuntu-reviewers team please also unsubscribe the team from this bug report.

[This is an automated message performed by a Launchpad user owned by Brian Murray. Please contact him regarding any issues with the action taken in this bug report.]

tags: added: patch
Revision history for this message
Torsten Spindler (tspindler) wrote :

A modified version of the patch, adding "ignore the apt-get update warning below" to the output. Background is, that if any error is detected during cachefile.cc pkgCacheFile::BuildCaches, apt will print the warning:
W: You may want to run apt-get update to correct these problems
In the case of an unreadable source list this is misleading.

The code printing the apt-get update warning:
   /* This sux, remove it someday */
   if (ErrorWasEmpty == true && _error->empty() == false)
      _error->Warning(_("You may want to run apt-get update to correct these problems"));

Revision history for this message
Torsten Spindler (tspindler) wrote :

Here is an alternate patch, using _error->Notice instead of _error->Warning. Using Notice leaves _error->empty false and hence the apt-get update warning is not printed. For comparison. here the output of the two patches:

apt-unreadable_sources.patch:

$ apt-cache policy apache2
apache2:
  Installed: (none)
  Candidate: 2.2.22-1ubuntu1
  Version table:
     2.2.22-1ubuntu1 0
        500 http://archive.ubuntu.com/ubuntu/ precise/main i386 Packages
     2.2.14-5ubuntu8 0
        500 http://archive.ubuntu.com/ubuntu/ lucid/main i386 Packages
W: Can not read /etc/apt/sources.list.d/a.list, ignore the apt-get update warning below
W: You may want to run apt-get update to correct these problems

apt-unreadable_sources_notice.patch:

$ apt-cache policy apache2
apache2:
  Installed: (none)
  Candidate: 2.2.22-1ubuntu1
  Version table:
     2.2.22-1ubuntu1 0
        500 http://archive.ubuntu.com/ubuntu/ precise/main i386 Packages
     2.2.14-5ubuntu8 0
        500 http://archive.ubuntu.com/ubuntu/ lucid/main i386 Packages
N: Can not read /etc/apt/sources.list.d/a.list.

Changed in apt (Ubuntu):
status: Triaged → In Progress
Revision history for this message
Julian Andres Klode (juliank) wrote :

We made things work better for unreadable files, so I think that's fixed in cosmic and probably bionic.

Changed in apt (Ubuntu):
status: In Progress → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.