~indicator-applet-developers/hud/trunk.14.04

« back to all changes in this revision

Viewing changes to service/DBusMenuCollector.cpp

  • Committer: CI bot
  • Author(s): Pete Woods, Marcus Tomlinson
  • Date: 2014-06-04 14:04:03 UTC
  • mfrom: (390.1.44 trunk)
  • Revision ID: ps-jenkins@lists.canonical.com-20140604140403-a70c33snru5b6k4x
Harden HUD against misbehaving applications

Report the offending applications using Apport's recoverable problem tool.
Switch to using shared pointers where possible for managing memory. Fixes: 1298656, 1316473, 1322050, 1325538

Show diffs side-by-side

added added

removed removed

Lines of Context:
82
82
        return !m_menuImporter.isNull();
83
83
}
84
84
 
85
 
inline uint qHash(const QStringList &key, uint seed) {
86
 
        uint hash(0);
87
 
        for (const QString &s : key) {
88
 
                hash ^= qHash(s, seed);
89
 
        }
90
 
        return hash;
91
 
}
92
 
 
93
85
void DBusMenuCollector::openMenu(QMenu *menu, unsigned int &limit) {
 
86
        --limit;
 
87
        if (limit == 0) {
 
88
                QString error = "Hit DBusMenu safety valve opening menu at " + m_service
 
89
                                + " " + m_path.path();
 
90
                throw std::logic_error(error.toStdString());
 
91
        }
 
92
 
94
93
        if (!menu) {
95
94
                return;
96
95
        }
97
96
 
98
 
        if (limit == 0) {
99
 
                QString error = "Hit DBusMenu safety valve for menu at " + m_service
100
 
                                + " " + m_path.path();
101
 
                throw std::logic_error(error.toStdString());
102
 
        }
103
 
 
104
97
        menu->aboutToShow();
105
98
 
106
99
        for (int i(0); m_menuImporter && i < menu->actions().size(); ++i) {
114
107
 
115
108
                QMenu *child(action->menu());
116
109
                if (child) {
117
 
                        --limit;
118
110
                        openMenu(child, limit);
119
111
                }
120
112
        }
121
113
}
122
114
 
123
115
void DBusMenuCollector::hideMenu(QMenu *menu, unsigned int &limit) {
 
116
        --limit;
124
117
        if (limit == 0) {
125
 
                QString error = "Hit DBusMenu safety valve for menu at " + m_service
 
118
                QString error = "Hit DBusMenu safety valve closing menu at " + m_service
126
119
                                + " " + m_path.path();
127
120
                throw std::logic_error(error.toStdString());
128
121
        }
131
124
                QAction *action = menu->actions().at(i);
132
125
                QMenu *child(action->menu());
133
126
                if (child) {
134
 
                        --limit;
135
127
                        hideMenu(child, limit);
136
128
                }
137
129
        }