Skip to content

Commit

Permalink
Updater: Don't create instance for invalid URL
Browse files Browse the repository at this point in the history
Also don't use dynamic_cast
For enterprise/#689
  • Loading branch information
guruz committed Jan 17, 2017
1 parent cd9e88a commit 588a88f
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 17 deletions.
3 changes: 2 additions & 1 deletion src/gui/generalsettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,8 @@ void GeneralSettings::loadMiscSettings()

void GeneralSettings::slotUpdateInfo()
{
OCUpdater *updater = dynamic_cast<OCUpdater*>(Updater::instance());
// Note: the sparkle-updater is not an OCUpdater
OCUpdater *updater = qobject_cast<OCUpdater*>(Updater::instance());
if (ConfigFile().skipUpdateCheck()) {
updater = 0; // don't show update info if updates are disabled
}
Expand Down
3 changes: 2 additions & 1 deletion src/gui/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,8 @@ int main(int argc, char **argv)
// if handleStartup returns true, main()
// needs to terminate here, e.g. because
// the updater is triggered
if (Updater::instance()->handleStartup()) {
Updater *updater = Updater::instance();
if ( updater && updater->handleStartup()) {
return true;
}

Expand Down
23 changes: 13 additions & 10 deletions src/gui/updater/ocupdater.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

#include "updater/ocupdater.h"

#include <QObject>
#include <QtCore>
#include <QtNetwork>
#include <QtGui>
Expand All @@ -43,9 +44,8 @@ UpdaterScheduler::UpdaterScheduler(QObject *parent) :
connect( &_updateCheckTimer, SIGNAL(timeout()),
this, SLOT(slotTimerFired()) );

// Note: the sparkle-updater is not an OCUpdater and thus the dynamic_cast
// returns NULL. Clever detail.
if (OCUpdater *updater = dynamic_cast<OCUpdater*>(Updater::instance())) {
// Note: the sparkle-updater is not an OCUpdater
if (OCUpdater *updater = qobject_cast<OCUpdater*>(Updater::instance())) {
connect(updater, SIGNAL(newUpdateAvailable(QString,QString)),
this, SIGNAL(updaterAnnouncement(QString,QString)) );
connect(updater, SIGNAL(requestRestart()), SIGNAL(requestRestart()));
Expand Down Expand Up @@ -76,14 +76,17 @@ void UpdaterScheduler::slotTimerFired()
return;
}

Updater::instance()->backgroundCheckForUpdate();
Updater *updater = Updater::instance();
if (updater) {
updater->backgroundCheckForUpdate();
}
}


/* ----------------------------------------------------------------- */

OCUpdater::OCUpdater(const QUrl &url, QObject *parent) :
QObject(parent)
OCUpdater::OCUpdater(const QUrl &url) :
Updater()
, _updateUrl(url)
, _state(Unknown)
, _accessManager(new AccessManager(this))
Expand Down Expand Up @@ -242,8 +245,8 @@ void OCUpdater::slotTimedOut()

////////////////////////////////////////////////////////////////////////

NSISUpdater::NSISUpdater(const QUrl &url, QObject *parent)
: OCUpdater(url, parent)
NSISUpdater::NSISUpdater(const QUrl &url)
: OCUpdater(url)
, _showFallbackMessage(false)
{
}
Expand Down Expand Up @@ -421,8 +424,8 @@ void NSISUpdater::slotSetSeenVersion()

////////////////////////////////////////////////////////////////////////

PassiveUpdateNotifier::PassiveUpdateNotifier(const QUrl &url, QObject *parent)
: OCUpdater(url, parent)
PassiveUpdateNotifier::PassiveUpdateNotifier(const QUrl &url)
: OCUpdater(url)
{
// remember the version of the currently running binary. On Linux it might happen that the
// package management updates the package while the app is running. This is detected in the
Expand Down
8 changes: 4 additions & 4 deletions src/gui/updater/ocupdater.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,15 +86,15 @@ private slots:
* @brief Class that uses an ownCloud proprietary XML format to fetch update information
* @ingroup gui
*/
class OCUpdater : public QObject, public Updater
class OCUpdater : public Updater
{
Q_OBJECT
public:
enum DownloadState { Unknown = 0, CheckingServer, UpToDate,
Downloading, DownloadComplete,
DownloadFailed, DownloadTimedOut,
UpdateOnlyAvailableThroughSystem };
explicit OCUpdater(const QUrl &url, QObject *parent = 0);
explicit OCUpdater(const QUrl &url);

bool performUpdate();

Expand Down Expand Up @@ -141,7 +141,7 @@ class NSISUpdater : public OCUpdater {
Q_OBJECT
public:
enum UpdateState { NoUpdate = 0, UpdateAvailable, UpdateFailed };
explicit NSISUpdater(const QUrl &url, QObject *parent = 0);
explicit NSISUpdater(const QUrl &url);
bool handleStartup() Q_DECL_OVERRIDE;
private slots:
void slotSetSeenVersion();
Expand All @@ -167,7 +167,7 @@ private slots:
class PassiveUpdateNotifier : public OCUpdater {
Q_OBJECT
public:
explicit PassiveUpdateNotifier(const QUrl &url, QObject *parent = 0);
explicit PassiveUpdateNotifier(const QUrl &url);
bool handleStartup() Q_DECL_OVERRIDE { return false; }
void backgroundCheckForUpdate() Q_DECL_OVERRIDE;

Expand Down
4 changes: 4 additions & 0 deletions src/gui/updater/updater.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,10 @@ Updater *Updater::create()
if (updateBaseUrl.isEmpty()) {
updateBaseUrl = QUrl(QLatin1String(APPLICATION_UPDATE_URL));
}
if (!updateBaseUrl.isValid() || updateBaseUrl.host() == ".") {
qDebug() << "Not a valid updater URL, will not do update check";
return 0;
}
updateBaseUrl = addQueryParams(updateBaseUrl);
#if defined(Q_OS_MAC) && defined(HAVE_SPARKLE)
updateBaseUrl.addQueryItem( QLatin1String("sparkle"), QLatin1String("true"));
Expand Down
4 changes: 3 additions & 1 deletion src/gui/updater/updater.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ class QUrl;

namespace OCC {

class Updater {
class Updater : public QObject {
Q_OBJECT
public:
struct Helper {
static qint64 stringVersionToInt(const QString& version);
Expand All @@ -37,6 +38,7 @@ class Updater {

protected:
static QString clientVersion();
Updater() : QObject(0) {}

private:
static QString getSystemInfo();
Expand Down

0 comments on commit 588a88f

Please sign in to comment.