From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on sa.local.altlinux.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=5.0 tests=ALL_TRUSTED,BAYES_00 autolearn=unavailable autolearn_force=no version=3.4.1 From: Aleksei Nikiforov To: devel@lists.altlinux.org Date: Thu, 12 Dec 2019 12:57:13 +0300 Message-Id: <20191212095730.83787-5-darktemplar@altlinux.org> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20191212095730.83787-1-darktemplar@altlinux.org> References: <20191211234857.GB17949@altlinux.org> <20191212095730.83787-1-darktemplar@altlinux.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Cc: Aleksei Nikiforov Subject: [devel] [PATCH for apt v2 04/21] Get rid of nullptr dereference X-BeenThere: devel@lists.altlinux.org X-Mailman-Version: 2.1.12 Precedence: list Reply-To: ALT Linux Team development discussions List-Id: ALT Linux Team development discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 12 Dec 2019 09:58:08 -0000 Archived-At: List-Archive: List-Post: 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