Skip to content

Commit c4f7398

Browse files
mchehabmasahir0y
authored andcommitted
kconfig: qconf: make debug links work again
The Qt5 conversion broke support for debug info links. Restore the behaviour added by changeset ab45d19 ("kconfig: create links in info window"). The original approach was to pass a pointer for a data struct via an <a href>. That doesn't sound a good idea, as, if something gets wrong, the app could crash. So, instead, pass the name of the symbol, and validate such symbol at the hyperlink handling logic. Link: https://lore.kernel.org/lkml/[email protected]/ Reported-by: Maxim Levitsky <[email protected]> Signed-off-by: Mauro Carvalho Chehab <[email protected]> Signed-off-by: Masahiro Yamada <[email protected]>
1 parent c699eaa commit c4f7398

File tree

2 files changed

+71
-5
lines changed

2 files changed

+71
-5
lines changed

scripts/kconfig/qconf.cc

Lines changed: 70 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include <QAction>
88
#include <QApplication>
99
#include <QCloseEvent>
10+
#include <QDebug>
1011
#include <QDesktopWidget>
1112
#include <QFileDialog>
1213
#include <QLabel>
@@ -1012,7 +1013,7 @@ ConfigInfoView::ConfigInfoView(QWidget* parent, const char *name)
10121013
: Parent(parent), sym(0), _menu(0)
10131014
{
10141015
setObjectName(name);
1015-
1016+
setOpenLinks(false);
10161017

10171018
if (!objectName().isEmpty()) {
10181019
configSettings->beginGroup(objectName());
@@ -1085,7 +1086,7 @@ void ConfigInfoView::menuInfo(void)
10851086
if (sym->name) {
10861087
head += " (";
10871088
if (showDebug())
1088-
head += QString().sprintf("<a href=\"s%p\">", sym);
1089+
head += QString().sprintf("<a href=\"s%s\">", sym->name);
10891090
head += print_filter(sym->name);
10901091
if (showDebug())
10911092
head += "</a>";
@@ -1094,7 +1095,7 @@ void ConfigInfoView::menuInfo(void)
10941095
} else if (sym->name) {
10951096
head += "<big><b>";
10961097
if (showDebug())
1097-
head += QString().sprintf("<a href=\"s%p\">", sym);
1098+
head += QString().sprintf("<a href=\"s%s\">", sym->name);
10981099
head += print_filter(sym->name);
10991100
if (showDebug())
11001101
head += "</a>";
@@ -1145,7 +1146,7 @@ QString ConfigInfoView::debug_info(struct symbol *sym)
11451146
switch (prop->type) {
11461147
case P_PROMPT:
11471148
case P_MENU:
1148-
debug += QString().sprintf("prompt: <a href=\"m%p\">", prop->menu);
1149+
debug += QString().sprintf("prompt: <a href=\"m%s\">", sym->name);
11491150
debug += print_filter(prop->text);
11501151
debug += "</a><br>";
11511152
break;
@@ -1217,13 +1218,74 @@ void ConfigInfoView::expr_print_help(void *data, struct symbol *sym, const char
12171218
QString str2 = print_filter(str);
12181219

12191220
if (sym && sym->name && !(sym->flags & SYMBOL_CONST)) {
1220-
*text += QString().sprintf("<a href=\"s%p\">", sym);
1221+
*text += QString().sprintf("<a href=\"s%s\">", sym->name);
12211222
*text += str2;
12221223
*text += "</a>";
12231224
} else
12241225
*text += str2;
12251226
}
12261227

1228+
void ConfigInfoView::clicked(const QUrl &url)
1229+
{
1230+
QByteArray str = url.toEncoded();
1231+
const std::size_t count = str.size();
1232+
char *data = new char[count + 1];
1233+
struct symbol **result;
1234+
struct menu *m = NULL;
1235+
char type;
1236+
1237+
if (count < 1) {
1238+
qInfo() << "Clicked link is empty";
1239+
delete data;
1240+
return;
1241+
}
1242+
1243+
memcpy(data, str.constData(), count);
1244+
data[count] = '\0';
1245+
type = data[0];
1246+
1247+
/* Seek for exact match */
1248+
data[0] = '^';
1249+
strcat(data, "$");
1250+
result = sym_re_search(data);
1251+
if (!result) {
1252+
qInfo() << "Clicked symbol is invalid:" << data;
1253+
delete data;
1254+
return;
1255+
}
1256+
1257+
sym = *result;
1258+
if (type == 's') {
1259+
symbolInfo();
1260+
emit showDebugChanged(true);
1261+
free(result);
1262+
delete data;
1263+
return;
1264+
}
1265+
1266+
/* URL is a menu */
1267+
for (struct property *prop = sym->prop; prop; prop = prop->next) {
1268+
if (prop->type != P_PROMPT && prop->type != P_MENU)
1269+
continue;
1270+
m = prop->menu;
1271+
break;
1272+
}
1273+
1274+
if (!m) {
1275+
qInfo() << "Clicked menu is invalid:" << data;
1276+
free(result);
1277+
delete data;
1278+
return;
1279+
}
1280+
1281+
_menu = m;
1282+
menuInfo();
1283+
1284+
emit showDebugChanged(true);
1285+
free(result);
1286+
delete data;
1287+
}
1288+
12271289
QMenu* ConfigInfoView::createStandardContextMenu(const QPoint & pos)
12281290
{
12291291
QMenu* popup = Parent::createStandardContextMenu(pos);
@@ -1497,6 +1559,9 @@ ConfigMainWindow::ConfigMainWindow(void)
14971559
helpMenu->addAction(showIntroAction);
14981560
helpMenu->addAction(showAboutAction);
14991561

1562+
connect (helpText, SIGNAL (anchorClicked (const QUrl &)),
1563+
helpText, SLOT (clicked (const QUrl &)) );
1564+
15001565
connect(configList, SIGNAL(menuChanged(struct menu *)),
15011566
helpText, SLOT(setInfo(struct menu *)));
15021567
connect(configList, SIGNAL(menuSelected(struct menu *)),

scripts/kconfig/qconf.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,7 @@ public slots:
250250
void setInfo(struct menu *menu);
251251
void saveSettings(void);
252252
void setShowDebug(bool);
253+
void clicked (const QUrl &url);
253254

254255
signals:
255256
void showDebugChanged(bool);

0 commit comments

Comments
 (0)