Skip to content

Commit

Permalink
Guard against null/invalid pointers to the network cache in getHeader…
Browse files Browse the repository at this point in the history
…(). Refs #10337
  • Loading branch information
stuartm committed Feb 21, 2012
1 parent 3e7f41e commit f6ca545
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
16 changes: 12 additions & 4 deletions mythtv/libs/libmythbase/mythdownloadmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -490,7 +490,7 @@ bool MythDownloadManager::download(QNetworkRequest *req, QByteArray *data)
* \param dest Destination filename.
* \param reload Whether to force reloading of the URL or not
* \param authCallback AuthCallback function for use with authentication
* \param authArg Opaque argument for callback function
* \param authArg Opaque argument for callback function
* \param header Optional HTTP header to add to the request
* \param headerVal Value for the optional HTTP header to add to the request
* \return true if download was successful, false otherwise.
Expand Down Expand Up @@ -590,7 +590,7 @@ bool MythDownloadManager::post(QNetworkRequest *req, QByteArray *data)
* \param url URL to post to
* \param data Location holding post and response data
* \param authCallback AuthCallback function for authentication
* \param authArg Opaque argument for callback function
* \param authArg Opaque argument for callback function
* \param header Optional HTTP header to add to the request
* \param headerVal Value for the optional HTTP header to add to the request
* \return true if post was successful, false otherwise.
Expand Down Expand Up @@ -689,7 +689,7 @@ void MythDownloadManager::downloadQNetworkRequest(MythDownloadInfo *dlInfo)
request.setRawHeader("User-Agent",
"MythTV v" MYTH_BINARY_VERSION " MythDownloadManager");

if (dlInfo->m_header && dlInfo->m_headerVal &&
if (dlInfo->m_header && dlInfo->m_headerVal &&
!dlInfo->m_header->isEmpty() && !dlInfo->m_headerVal->isEmpty())
{
request.setRawHeader(*(dlInfo->m_header), *(dlInfo->m_headerVal));
Expand Down Expand Up @@ -1327,6 +1327,14 @@ void MythDownloadManager::saveCookieJar(const QString &filename)
jar->save(filename);
}

QString MythDownloadManager::getHeader(const QUrl& url, const QString& header)
{
if (!m_manager || !m_manager->cache())
return QString::null;

return getHeader(m_manager->cache()->metaData(url), header);
}

/** \brief Gets the value of an HTTP header from the cache
* \param cacheData The cache data to search through
* \param header Which HTTP header to get the value of
Expand Down Expand Up @@ -1363,7 +1371,7 @@ void MythCookieJar::load(const QString &filename)
QString cookie = stream.readLine();
cookieList << QNetworkCookie::parseCookies(cookie.toLocal8Bit());
}

setAllCookies(cookieList);
}

Expand Down
4 changes: 2 additions & 2 deletions mythtv/libs/libmythbase/mythdownloadmanager.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ class MBASE_PUBLIC MythDownloadManager : public QObject, public MThread
void queuePost(QNetworkRequest *req, QByteArray *data, QObject *caller);
bool post(const QString &url, QByteArray *data);
bool post(QNetworkRequest *req, QByteArray *data);
bool postAuth(const QString &url, QByteArray *data,
bool postAuth(const QString &url, QByteArray *data,
AuthCallback authCallback, void *authArg,
const QByteArray *header = NULL,
const QByteArray *headerVal = NULL);
Expand All @@ -82,7 +82,7 @@ class MBASE_PUBLIC MythDownloadManager : public QObject, public MThread
QNetworkCookieJar *getCookieJar(void) { return m_manager->cookieJar(); }
void setCookieJar(QNetworkCookieJar *cookieJar) { m_manager->setCookieJar(cookieJar); }

QString getHeader(const QUrl &url, const QString &header) { return getHeader(m_manager->cache()->metaData(url), header); }
QString getHeader(const QUrl &url, const QString &header);
QString getHeader(const QNetworkCacheMetaData &cacheData, const QString &header);

private slots:
Expand Down

0 comments on commit f6ca545

Please sign in to comment.