mirror of
https://bitbucket.org/smil3y/kde-workspace.git
synced 2025-02-23 18:32:50 +00:00
kdirshare: fix possible crash in case of null KMimeType pointer
Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
This commit is contained in:
parent
3c9e044b03
commit
85e1e8a8ea
1 changed files with 14 additions and 11 deletions
|
@ -53,6 +53,18 @@ static QString getShareName(const QString &dirpath)
|
||||||
return dirname;
|
return dirname;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static QString getFileMIME(const QString &filepath)
|
||||||
|
{
|
||||||
|
const KMimeType::Ptr kmimetypeptr = KMimeType::findByUrl(
|
||||||
|
KUrl(filepath),
|
||||||
|
mode_t(0), true
|
||||||
|
);
|
||||||
|
if (!kmimetypeptr.isNull()) {
|
||||||
|
return kmimetypeptr->name();
|
||||||
|
}
|
||||||
|
return QString::fromLatin1("application/octet-stream");
|
||||||
|
}
|
||||||
|
|
||||||
static QByteArray contentForDirectory(const QString &path, const QString &basedir)
|
static QByteArray contentForDirectory(const QString &path, const QString &basedir)
|
||||||
{
|
{
|
||||||
QByteArray data;
|
QByteArray data;
|
||||||
|
@ -100,7 +112,7 @@ static QByteArray contentForDirectory(const QString &path, const QString &basedi
|
||||||
|
|
||||||
data.append("<td>");
|
data.append("<td>");
|
||||||
if (!isdotdot) {
|
if (!isdotdot) {
|
||||||
const QString filemime = KMimeType::findByPath(fullpath)->name();
|
const QString filemime = getFileMIME(fullpath);
|
||||||
data.append(filemime.toAscii());
|
data.append(filemime.toAscii());
|
||||||
}
|
}
|
||||||
data.append("</td>");
|
data.append("</td>");
|
||||||
|
@ -218,16 +230,7 @@ void KDirShareImpl::respond(const QByteArray &url, QByteArray *outdata,
|
||||||
*outhttpstatus = 500;
|
*outhttpstatus = 500;
|
||||||
outheaders->insert("Content-Type", "text/html; charset=UTF-8");
|
outheaders->insert("Content-Type", "text/html; charset=UTF-8");
|
||||||
} else {
|
} else {
|
||||||
QString filemime;
|
const QString filemime = getFileMIME(pathinfo.filePath());
|
||||||
const KMimeType::Ptr kmimetypeptr = KMimeType::findByUrl(
|
|
||||||
KUrl(pathinfo.filePath()),
|
|
||||||
mode_t(0), true
|
|
||||||
);
|
|
||||||
if (!kmimetypeptr.isNull()) {
|
|
||||||
filemime = kmimetypeptr->name();
|
|
||||||
} else {
|
|
||||||
filemime = QString::fromLatin1("application/octet-stream");
|
|
||||||
}
|
|
||||||
*outhttpstatus = 200;
|
*outhttpstatus = 200;
|
||||||
outheaders->insert("Content-Type", QString::fromLatin1("%1; charset=UTF-8").arg(filemime).toAscii());
|
outheaders->insert("Content-Type", QString::fromLatin1("%1; charset=UTF-8").arg(filemime).toAscii());
|
||||||
outfilepath->append(pathinfo.filePath());
|
outfilepath->append(pathinfo.filePath());
|
||||||
|
|
Loading…
Add table
Reference in a new issue