~ubuntu-branches/ubuntu/precise/kde-runtime/precise-updates

« back to all changes in this revision

Viewing changes to .pc/upstream_CVE-2014-8600.diff/kioslave/bookmarks/kio_bookmarks.cpp

  • Committer: Package Import Robot
  • Author(s): Jonathan Riddell
  • Date: 2014-11-20 15:46:42 UTC
  • mfrom: (18.1.5 precise-proposed)
  • Revision ID: package-import@ubuntu.com-20141120154642-hyesdbuvsk78ihtz
Tags: 4:4.8.5-0ubuntu0.3
* SECURITY UPDATE: Insufficient Input Validation By IO Slaves and
  Webkit Part
 - Add upstream_CVE-2014-8600.diff to escape protocol twice: once
   for i18n, and once for HTML
 - https://www.kde.org/info/security/advisory-20141113-1.txt
 - CVE-2014-8600
 - LP: #1393479

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
   Copyright (C) 2008 Xavier Vello <xavier.vello@gmail.com>
 
3
 
 
4
   This program is free software; you can redistribute it and/or modify
 
5
   it under the terms of the GNU General Public License as published by
 
6
   the Free Software Foundation; either version 2 of the License, or
 
7
   (at your option) any later version.
 
8
 
 
9
   This program is distributed in the hope that it will be useful,
 
10
   but WITHOUT ANY WARRANTY; without even the implied warranty of
 
11
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 
12
   GNU General Public License for more details.
 
13
 
 
14
   You should have received a copy of the GNU General Public License
 
15
   along with this program; if not, write to the Free Software
 
16
   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 
17
*/
 
18
 
 
19
#include "kio_bookmarks.h"
 
20
 
 
21
#include <stdio.h>
 
22
#include <stdlib.h>
 
23
 
 
24
#include <qregexp.h>
 
25
 
 
26
#include <kapplication.h>
 
27
#include <kcmdlineargs.h>
 
28
#include <kaboutdata.h>
 
29
 
 
30
#include <kshell.h>
 
31
#include <kstandarddirs.h>
 
32
#include <kcomponentdata.h>
 
33
#include <klocale.h>
 
34
#include <kconfig.h>
 
35
#include <kconfiggroup.h>
 
36
#include <kbookmark.h>
 
37
#include <kbookmarkmanager.h>
 
38
#include <kimagecache.h>
 
39
#include <kdebug.h>
 
40
#include <kfileplacesmodel.h>
 
41
#include <solid/device.h>
 
42
#include <solid/deviceinterface.h>
 
43
#include <ktoolinvocation.h>
 
44
 
 
45
using namespace KIO;
 
46
 
 
47
BookmarksProtocol::BookmarksProtocol( const QByteArray &pool, const QByteArray &app )
 
48
  : SlaveBase( "bookmarks", pool, app )
 
49
{
 
50
  manager = KBookmarkManager::userBookmarksManager();
 
51
  cfg = new KConfig( "kiobookmarksrc" );
 
52
  config = cfg->group("General");
 
53
  cache = new KImageCache("kio_bookmarks", config.readEntry("CacheSize", 5 * 1024) * 1024);
 
54
  cache->setPixmapCaching(false);
 
55
 
 
56
  indent = 0;
 
57
  totalsize = 0;
 
58
  columns = 4;
 
59
}
 
60
 
 
61
BookmarksProtocol::~BookmarksProtocol()
 
62
{
 
63
  delete manager;
 
64
  delete cache;
 
65
  delete cfg;
 
66
}
 
67
 
 
68
void BookmarksProtocol::parseTree()
 
69
{
 
70
  totalsize = 0;
 
71
 
 
72
  cfg->reparseConfiguration();
 
73
  columns =  config.readEntry("Columns", 4);
 
74
  if (columns < 1)
 
75
    columns = 1;
 
76
 
 
77
  manager->notifyCompleteChange("kio_bookmarks");
 
78
  tree = manager->root();
 
79
 
 
80
  if(tree.first().isNull())
 
81
    return;
 
82
 
 
83
  if(config.readEntry("FlattenTree", false))
 
84
    flattenTree(tree);
 
85
 
 
86
  KBookmarkGroup root;
 
87
  if(config.readEntry("ShowRoot", true))
 
88
  {
 
89
    root = tree.createNewFolder(i18n("Root"));
 
90
    tree.moveBookmark(root, KBookmark());
 
91
    root.setIcon("konqueror");
 
92
  }
 
93
 
 
94
    KBookmark bm = tree.first();
 
95
    KBookmark next;
 
96
    while(!bm.isNull())
 
97
    {
 
98
      next = tree.next(bm);
 
99
      if (bm.isSeparator())
 
100
        tree.deleteBookmark(bm);
 
101
      else if (bm.isGroup())
 
102
        totalsize += sizeOfGroup(bm.toGroup());
 
103
      else
 
104
      {
 
105
        if(config.readEntry("ShowRoot", true))
 
106
          root.addBookmark(bm);
 
107
 
 
108
        tree.deleteBookmark(bm);
 
109
      }
 
110
      bm = next;
 
111
    }
 
112
    if(config.readEntry("ShowRoot", true))
 
113
      totalsize += sizeOfGroup(root);
 
114
 
 
115
    if(config.readEntry("ShowPlaces", true))
 
116
      totalsize += addPlaces();
 
117
}
 
118
 
 
119
int BookmarksProtocol::addPlaces()
 
120
{
 
121
  KFilePlacesModel placesModel;
 
122
  KBookmarkGroup folder = tree.createNewFolder(i18n("Places"));
 
123
  QList<Solid::Device> batteryList = Solid::Device::listFromType(Solid::DeviceInterface::Battery, QString());
 
124
 
 
125
  if (batteryList.isEmpty()) {
 
126
    folder.setIcon("computer");
 
127
  } else {
 
128
    folder.setIcon("computer-laptop");
 
129
  }
 
130
 
 
131
  for (int row = 0; row < placesModel.rowCount(); ++row) {
 
132
    QModelIndex index = placesModel.index(row, 0);
 
133
 
 
134
    if (!placesModel.isHidden(index))
 
135
      folder.addBookmark(placesModel.bookmarkForIndex(index));
 
136
  }
 
137
  return sizeOfGroup(folder);
 
138
}
 
139
 
 
140
void BookmarksProtocol::flattenTree( const KBookmarkGroup &folder )
 
141
{
 
142
  KBookmark bm = folder.first();
 
143
  KBookmark prev = folder;
 
144
  KBookmark next;
 
145
  while (!bm.isNull())
 
146
  {
 
147
    if (bm.isGroup()) {
 
148
      flattenTree(bm.toGroup());
 
149
    }
 
150
 
 
151
    next = tree.next(bm);
 
152
 
 
153
    if (bm.isGroup() && bm.parentGroup().hasParent()) {
 
154
      kDebug() << "moving " << bm.text() << " from " << bm.parentGroup().fullText() << " to " << prev.parentGroup().text() << endl;
 
155
 
 
156
      bm.setFullText("| " + bm.parentGroup().fullText() + " > " + bm.fullText());
 
157
      tree.moveBookmark(bm, prev);
 
158
      prev = bm;
 
159
    }
 
160
    bm = next;
 
161
  }
 
162
}
 
163
 
 
164
// Should really go to KBookmarkGroup
 
165
int BookmarksProtocol::sizeOfGroup( const KBookmarkGroup &folder, bool real )
 
166
{
 
167
  int size = 1;  // counting the title line
 
168
  for (KBookmark bm = folder.first(); !bm.isNull(); bm = folder.next(bm))
 
169
  {
 
170
    if (bm.isGroup())
 
171
      size += sizeOfGroup(bm.toGroup());
 
172
    else
 
173
      size += 1;
 
174
  }
 
175
 
 
176
  // CSS sets a min-height for toplevel folders
 
177
  if (folder.parentGroup() == tree && size < 8 && real == false)
 
178
    size = 8;
 
179
 
 
180
  return size;
 
181
}
 
182
 
 
183
void BookmarksProtocol::get( const KUrl& url )
 
184
{
 
185
  QString path = url.path();
 
186
  QRegExp regexp("^/(background|icon)/([\\S]+)");
 
187
 
 
188
  if (path.isEmpty() || path == "/") {
 
189
    echoIndex();
 
190
  } else if (path == "/config") {
 
191
    KToolInvocation::startServiceByDesktopName("bookmarks", "");
 
192
    echoHead("bookmarks:/");
 
193
  } else if (path == "/editbookmarks") {
 
194
    KToolInvocation::kdeinitExec("keditbookmarks");
 
195
    echoHead("bookmarks:/");
 
196
  } else if (regexp.indexIn(path) >= 0) {
 
197
    echoImage(regexp.cap(1), regexp.cap(2), url.queryItem("size"));
 
198
  } else {
 
199
    echoHead();
 
200
    echo("<p class=\"message\">" + i18n("Wrong request: %1",path) + "</p>");
 
201
  }
 
202
  finished();
 
203
}
 
204
 
 
205
extern "C" int KDE_EXPORT kdemain(int argc, char **argv)
 
206
{
 
207
  KAboutData about("kio_bookmarks", 0, ki18n("My bookmarks"), "0.2.2");
 
208
  about.addLicense(KAboutData::License_GPL_V2);
 
209
  about.addAuthor(ki18n("Xavier Vello"), ki18n("Initial developer"), "xavier.vello@gmail.com", QByteArray());
 
210
  KCmdLineArgs::init(&about);
 
211
  KApplication app;
 
212
 
 
213
  if (argc != 4) {
 
214
      kError() << "Usage: kio_bookmarks protocol domain-socket1 domain-socket2";
 
215
      exit(-1);
 
216
  }
 
217
 
 
218
  BookmarksProtocol slave(argv[2], argv[3]);
 
219
  slave.dispatchLoop();
 
220
 
 
221
  return 0;
 
222
}