summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJulian Andres Klode <julian.klode@canonical.com>2024-05-22 22:46:31 +0200
committerJulian Andres Klode <julian.klode@canonical.com>2024-05-22 22:48:04 +0200
commit140d36fd16a3d4f1fce0c54474b946d0577f1fde (patch)
treea3ccfa6cb178a06033155e155a88e0a9175bdeee
parent3347b7a00682a0498a2602ce3e4e72c2c3d49c75 (diff)
pkgcachegen: Do not try to chmod or write to /dev/null
When -o Dir::Cache::pkgcache or -o Dir::Cache is set to /dev/null we accidentally changed its mode to 0666; which is certainly not intended. Avoid this issue by exiting the function early if the file specified is /dev/null.
-rw-r--r--apt-pkg/pkgcachegen.cc4
1 files changed, 4 insertions, 0 deletions
diff --git a/apt-pkg/pkgcachegen.cc b/apt-pkg/pkgcachegen.cc
index 504756104..981d360d2 100644
--- 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;
+
FileFd SCacheF(FileName, FileFd::WriteAtomic);
if (SCacheF.IsOpen() == false || SCacheF.Failed())
return false;