[devel] [PATCH for apt v2 04/21] Get rid of nullptr dereference
Aleksei Nikiforov
darktemplar на altlinux.org
Чт Дек 12 12:57:13 MSK 2019
Found via cppcheck:
(warning) Possible null pointer dereference: CmdL
---
apt/cmdline/apt-get.cc | 22 +++++++++++++++++-----
apt/cmdline/apt-shell.cc | 34 +++++++++++++++++++++++-----------
2 files changed, 40 insertions(+), 16 deletions(-)
diff --git a/apt/cmdline/apt-get.cc b/apt/cmdline/apt-get.cc
index 3858752..1eff3eb 100644
--- a/apt/cmdline/apt-get.cc
+++ b/apt/cmdline/apt-get.cc
@@ -190,6 +190,8 @@ bool CheckOnly(CacheFile &Cache)
// CNC:2002-07-06
bool DoClean(CommandLine &CmdL);
bool DoAutoClean(CommandLine &CmdL);
+static bool DoCleanImpl();
+static bool DoAutoCleanImpl();
// InstallPackages - Actually download and install the packages /*{{{*/
// ---------------------------------------------------------------------
@@ -508,11 +510,10 @@ bool InstallPackages(CacheFile &Cache,bool ShwKept,bool Ask = true,
// CNC:2002-07-06
if (Res == pkgPackageManager::Completed)
{
- CommandLine *CmdL = NULL; // Watch out! If used will blow up!
if (_config->FindB("APT::Post-Install::Clean",false) == true)
- Ret &= DoClean(*CmdL);
+ Ret &= DoCleanImpl();
else if (_config->FindB("APT::Post-Install::AutoClean",false) == true)
- Ret &= DoAutoClean(*CmdL);
+ Ret &= DoAutoCleanImpl();
return Ret;
}
@@ -1790,7 +1791,7 @@ bool DoDSelectUpgrade(CommandLine &CmdL)
// DoClean - Remove download archives /*{{{*/
// ---------------------------------------------------------------------
/* */
-bool DoClean(CommandLine &CmdL)
+static bool DoCleanImpl()
{
if (_config->FindB("APT::Get::Simulate") == true)
{
@@ -1813,6 +1814,12 @@ bool DoClean(CommandLine &CmdL)
Fetcher.Clean(_config->FindDir("Dir::Cache::archives") + "partial/");
return true;
}
+
+bool DoClean(CommandLine &CmdL)
+{
+ return DoCleanImpl();
+}
+
/*}}}*/
// DoAutoClean - Smartly remove downloaded archives /*{{{*/
// ---------------------------------------------------------------------
@@ -1830,7 +1837,7 @@ class LogCleaner : public pkgArchiveCleaner
};
};
-bool DoAutoClean(CommandLine &CmdL)
+static bool DoAutoCleanImpl()
{
// Lock the archive directory
FileFd Lock;
@@ -1850,6 +1857,11 @@ bool DoAutoClean(CommandLine &CmdL)
return Cleaner.Go(_config->FindDir("Dir::Cache::archives"),*Cache) &&
Cleaner.Go(_config->FindDir("Dir::Cache::archives") + "partial/",*Cache);
}
+
+bool DoAutoClean(CommandLine &CmdL)
+{
+ return DoAutoCleanImpl();
+}
/*}}}*/
// DoCheck - Perform the check operation /*{{{*/
// ---------------------------------------------------------------------
diff --git a/apt/cmdline/apt-shell.cc b/apt/cmdline/apt-shell.cc
index 0aa5da5..d192783 100644
--- a/apt/cmdline/apt-shell.cc
+++ b/apt/cmdline/apt-shell.cc
@@ -261,6 +261,8 @@ bool ConfirmChanges(CacheFile &Cache, AutoRestore &StateGuard)
// CNC:2002-07-06
bool DoClean(CommandLine &CmdL);
bool DoAutoClean(CommandLine &CmdL);
+static bool DoCleanImpl();
+static bool DoAutoCleanImpl();
// InstallPackages - Actually download and install the packages /*{{{*/
// ---------------------------------------------------------------------
@@ -565,11 +567,10 @@ bool InstallPackages(CacheFile &Cache,bool ShwKept,bool Ask = true,
// CNC:2002-07-06
if (Res == pkgPackageManager::Completed)
{
- CommandLine *CmdL = NULL; // Watch out! If used will blow up!
if (_config->FindB("APT::Post-Install::Clean",false) == true)
- Ret &= DoClean(*CmdL);
+ Ret &= DoCleanImpl();
else if (_config->FindB("APT::Post-Install::AutoClean",false) == true)
- Ret &= DoAutoClean(*CmdL);
+ Ret &= DoAutoCleanImpl();
if (Ret)
{
@@ -1611,11 +1612,8 @@ bool DoDSelectUpgrade(CommandLine &CmdL)
// DoClean - Remove download archives /*{{{*/
// ---------------------------------------------------------------------
/* */
-bool DoClean(CommandLine &CmdL)
+static bool DoCleanImpl()
{
- if (CheckHelp(CmdL,0) == true)
- return true;
-
if (_config->FindB("APT::Get::Simulate") == true)
{
cout << "Del " << _config->FindDir("Dir::Cache::archives") << "* " <<
@@ -1637,6 +1635,14 @@ bool DoClean(CommandLine &CmdL)
Fetcher.Clean(_config->FindDir("Dir::Cache::archives") + "partial/");
return true;
}
+
+bool DoClean(CommandLine &CmdL)
+{
+ if (CheckHelp(CmdL,0) == true)
+ return true;
+
+ return DoCleanImpl();
+}
/*}}}*/
// DoAutoClean - Smartly remove downloaded archives /*{{{*/
// ---------------------------------------------------------------------
@@ -1654,11 +1660,8 @@ class LogCleaner : public pkgArchiveCleaner
};
};
-bool DoAutoClean(CommandLine &CmdL)
+static bool DoAutoCleanImpl()
{
- if (CheckHelp(CmdL,0) == true)
- return true;
-
// Lock the archive directory
FileFd Lock;
if (_config->FindB("Debug::NoLocking",false) == false)
@@ -1679,6 +1682,15 @@ bool DoAutoClean(CommandLine &CmdL)
return Cleaner.Go(_config->FindDir("Dir::Cache::archives"),*Cache) &&
Cleaner.Go(_config->FindDir("Dir::Cache::archives") + "partial/",*Cache);
}
+
+bool DoAutoClean(CommandLine &CmdL)
+{
+ if (CheckHelp(CmdL,0) == true)
+ return true;
+
+ return DoAutoCleanImpl();
+}
+
/*}}}*/
// DoCheck - Perform the check operation /*{{{*/
// ---------------------------------------------------------------------
--
2.24.1
Подробная информация о списке рассылки Devel