Dir::Cache=/dev/null chmods /dev/null

Bug #2067138 reported by Julian Andres Klode
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
apt (Ubuntu)
Fix Released
Undecided
Unassigned

Bug Description

[Impact]
If you set Dir::Cache or Dir::Cache::pkgcache to /dev/null, /dev/null is chmodded as we chmod the cache file to 666. This is a semi-common pattern to not use a cache, and breaks user scripts.

[Test plan]
1. autopkgtests run the large integration test suite
2. run manually
   apt-cache gencaches -o Dir::Cache::pkgcache=/dev/null
   apt-cache gencaches -o Dir::Cache::srcpkgcache=/dev/null
   apt-cache gencaches -o Dir::Cache=/dev/null
   and observe that /dev/null is still correct.

[Where problems could occur]
We have eliminated writing the cache to /dev/null entirely:

--- a/apt-pkg/pkgcachegen.cc
+++ b/apt-pkg/pkgcachegen.cc
@@ -1637,6 +1637,10 @@ static DynamicMMap* CreateDynamicMMap(FileFd * const CacheF, unsigned long Flags
 static bool writeBackMMapToFile(pkgCacheGenerator * const Gen, DynamicMMap * const Map,
       std::string const &FileName)
 {
+ // Do not write the file back to /dev/null or try to change its mode...
+ if (FileName == "/dev/null")
+ return true;

It's possible we may introduce issues later because something in there does fancy bits and the cache in memory becomes invalid, but so far I only saw that we calculate the hash in there, but we set dirty afterwards and don't actually use the cache hash if we don't load from disk so I think in reality this is not a problem, at least now. Just gotta be careful to not stuff anything other than writing in there.

Revision history for this message
Launchpad Janitor (janitor) wrote :

This bug was fixed in the package apt - 2.9.5

---------------
apt (2.9.5) unstable; urgency=medium

  [ Julian Andres Klode ]
  * CI: Set /bin/sh shell for travis user, so flock -c works
  * Fix test cases for non-amd64 architectures
  * edsp: Parse source version from the Source-Version field
  * Check gpgv --dump-options for --assert-pubkey-algo support.
    Thanks to Justus Winter for the idea
  * Make the failure mode for non-executable tests stronger
  * solver3: Do not dump sizes that are clearly pointers
  * solver3: Group work items
  * solver3: Remove no longer necessary comparisons
  * solver3: Order obsolete choices last

  [ Noah Meyerhans ]
  * Fix spelling of @SNAPSHOTID@ in apt.conf.5.xml (Closes: #1072189)

  [ Frans Spiesschaert ]
  * Dutch program translation update (Closes: #1072493)
  * Dutch manpages translation update (Closes: #1072494)

 -- Julian Andres Klode <email address hidden> Thu, 13 Jun 2024 21:04:40 +0200

Changed in apt (Ubuntu):
status: New → 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.