diff --git a/man/kio_man.cpp b/man/kio_man.cpp --- a/man/kio_man.cpp +++ b/man/kio_man.cpp @@ -571,8 +571,20 @@ { qCDebug(KIO_MAN_LOG) << "not existing " << filename; QDir mandir(lastdir); - mandir.setNameFilters(QStringList() << (filename.mid(filename.lastIndexOf('/') + 1) + ".*")); - filename = lastdir + '/' + QFile::encodeName(mandir.entryList().first()); + const QString nameFilter = filename.mid(filename.lastIndexOf('/') + 1) + ".*"; + mandir.setNameFilters(QStringList(nameFilter)); + + const QStringList entries = mandir.entryList(); + if (entries.isEmpty()) + { + outputError(i18n("The specified man page referenced another page '%1',
" + "but the referenced page '%2' could not be found.", + QFile::decodeName(filename), + QDir::cleanPath(lastdir + '/' + nameFilter))); + return 0; + } + + filename = lastdir + '/' + QFile::encodeName(entries.first()); qCDebug(KIO_MAN_LOG) << "resolved to " << filename; } diff --git a/man/man2html.cpp b/man/man2html.cpp --- a/man/man2html.cpp +++ b/man/man2html.cpp @@ -3995,6 +3995,24 @@ h = name + 3; else h = name; + + // The format of the argument to .so varies among man pages. + // Some of them, e.g. pam.8, use "PAM.8". Others, e.g. telinit.8, + // use "man8/init.8". So they are not always true relative paths, + // although the man(1) command seems to handle them with no problem. + // + // The code above starting "h = c - 3" attempts to turn the argument + // into a relative path, but that is not correct in the case of pam.8 + // as above. So this removes the "../" prefix again if there is + // no other slash following it. + char *firstSlash = strchr(h, '/'); + if (firstSlash != 0) + { + char *nextSlash = strchr(firstSlash + 1, '/'); + if (nextSlash == 0) + h = firstSlash + 1; + } + /* this works alright, except for section 3 */ buf = read_man_page(h); if (!buf)