• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

IJHack / QtPass / 46256559824

29 Nov 2026 11:18AM UTC coverage: 94.504% (+0.01%) from 94.493%
46256559824

push

github

web-flow
pass backend: ask before a pass run gives entries new readers (#2391)

pass init, pass mv and pass cp re-encrypt every entry of a folder
themselves; mv and cp end with reencrypt_path on where the moved item
landed. An entry someone with push access copied in from a folder you
are not on was handed to the folder's recipients by your next Users
save, or by a move, rename or copy that touched its folder.

RealPass::entriesInitWouldWiden() and entriesMoveWouldWiden() name,
before pass runs, the entries it would re-encrypt that would become
readable by someone on their target list who cannot read them now: a
throwaway encryption to the list (Pass::encryptionReaches()) against the
entry's recipient IDs (Pass::entryReaders(), path translated for a WSL
gpg), less whom the change adds. A list the probe cannot read, or an
entry whose recipients cannot be listed, is asked about. For a move,
both the entries already in the destination folder and those inside a
folder that moves are checked, each against the list it will get. The
Users dialog, a drop in the tree and MainWindow's move and rename ask,
under a wait cursor (PlainMessageBox::confirmPassRun()); No runs
nothing, Yes lets pass go on as before.

Tests: with a fake gpg whose ciphertext lists its recipients, a planted
copy is named for a Users save, a move into its folder and a rename of
its folder; an entry the change adds someone to is not; an unlistable
entry is asked about. The Users dialog and a tree drop ask, and No runs
nothing. Each guard was reverted once and its test failed.

Scan finding ANT-2026-SEN4VBBB.

Signed-off-by: Anne Jan Brouwer <brouwer@annejan.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

126 of 132 new or added lines in 7 files covered. (95.45%)

11039 of 11681 relevant lines covered (94.5%)

23924.6 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

96.88
/src/plainmessagebox.cpp
1
// SPDX-FileCopyrightText: 2026 Anne Jan Brouwer
2
// SPDX-License-Identifier: GPL-3.0-or-later
3
/**
4
 * @file
5
 * @brief Implements the PlainMessageBox helpers; the text format is set before
6
 * the text so it is never laid out as rich text.
7
 */
8
#include "plainmessagebox.h"
9
#include "util.h"
10
#include <QApplication>
11
#include <QCoreApplication>
12
#include <QDir>
13

14
namespace {
15
/// Lines and characters of a message a box shows whole.
16
constexpr qsizetype kMaxLines = 40;
17
/// See kMaxLines.
18
constexpr qsizetype kMaxChars = 4000;
19
/// Characters of a message kept whole under "Show Details...".
20
constexpr qsizetype kMaxDetailChars = 256 * 1024;
21

22
/**
23
 * @brief The first @p chars UTF-16 units of @p text, or its last with
24
 * @p fromEnd, one fewer where the cut would split a surrogate pair: half a
25
 * pair shows as a broken glyph.
26
 * @param text The text.
27
 * @param chars The most UTF-16 units.
28
 * @param fromEnd Take the end, not the start.
29
 * @return That part of @p text, valid UTF-16 where @p text is.
30
 */
31
auto slice(const QString &text, qsizetype chars, bool fromEnd) -> QString {
24 ✔
32
  if (chars >= text.size()) {
24 ✔
33
    return text;
34
  }
35
  if (fromEnd) {
24 ✔
36
    const qsizetype from = text.size() - chars;
12 ✔
37
    return text.right(text.at(from).isLowSurrogate() ? chars - 1 : chars);
12 ✔
38
  }
39
  return text.left(text.at(chars - 1).isHighSurrogate() ? chars - 1 : chars);
14 ✔
40
}
41

42
/**
43
 * @brief At most @p lines lines and @p chars characters from the start of
44
 * @p text, or from its end with @p fromEnd.
45
 * @param text The text.
46
 * @param lines The most lines.
47
 * @param chars The most characters.
48
 * @param fromEnd Take the end, not the start.
49
 * @return That part of @p text.
50
 */
51
auto part(const QString &text, qsizetype lines, qsizetype chars, bool fromEnd)
18 ✔
52
    -> QString {
53
  QString piece = slice(text, chars, fromEnd);
18 ✔
54
  qsizetype seen = 0;
55
  if (fromEnd) {
18 ✔
56
    for (qsizetype i = piece.size() - 1; i >= 0; --i) {
16,390 ✔
57
      if (piece.at(i) == QLatin1Char('\n') && ++seen == lines) {
16,382 ✔
58
        return piece.mid(i + 1);
1 ✔
59
      }
60
    }
61
  } else {
62
    for (qsizetype i = 0; i < piece.size(); ++i) {
16,337 ✔
63
      if (piece.at(i) == QLatin1Char('\n') && ++seen == lines) {
16,329 ✔
64
        return piece.left(i);
1 ✔
65
      }
66
    }
67
  }
68
  return piece;
69
}
70

71
/**
72
 * @brief @p text as a box shows it: whole up to kMaxLines lines and
73
 * kMaxChars characters, else its start and its end with an ellipsis
74
 * between.
75
 *
76
 * A message quoting git's or gpg's error output is as long as that output,
77
 * and a pushed .gitattributes with many bad lines decides its length: laid
78
 * out whole, the box froze the GUI. The end stays because that is where git
79
 * puts what went wrong ("fatal: ..."), after its warnings.
80
 * @param text The message.
81
 * @param cut Set to whether anything was left out.
82
 * @return The message to show.
83
 */
84
auto bounded(const QString &text, bool *cut) -> QString {
64 ✔
85
  *cut = text.size() > kMaxChars || text.count(QLatin1Char('\n')) >= kMaxLines;
64 ✔
86
  if (!*cut) {
64 ✔
87
    return text;
88
  }
89
  return part(text, kMaxLines / 2, kMaxChars / 2, false) +
18 ✔
90
         QStringLiteral("\n\u2026\n") +
18 ✔
91
         part(text, kMaxLines / 2, kMaxChars / 2, true);
27 ✔
92
}
93
} // namespace
94

95
auto PlainMessageBox::show(QWidget *parent, QMessageBox::Icon icon,
64 ✔
96
                           const QString &title, const QString &text,
97
                           QMessageBox::StandardButtons buttons)
98
    -> QMessageBox::StandardButton {
99
  QMessageBox box(parent);
64 ✔
100
  box.setIcon(icon);
64 ✔
101
  // The text quotes names from the store: a bidi override in a folder name
102
  // mirrored the rest of a warning, a C1 control cut it short.
103
  box.setWindowTitle(Util::displayable(title, false));
64 ✔
104
  // Before the text: set afterwards, the text would already have been laid
105
  // out as rich text once.
106
  box.setTextFormat(Qt::PlainText);
64 ✔
107
  const QString shown = Util::displayable(text);
64 ✔
108
  bool cut = false;
64 ✔
109
  box.setText(bounded(shown, &cut));
64 ✔
110
  if (cut) {
64 ✔
111
    // All of it under "Show Details...": plain text in a scrolling field,
112
    // which does not lay it out at once as the label did. Not all tool
113
    // output reaches the Process Output panel (the set-up runs git while
114
    // the window waits), so this is where the cause can be read. Past
115
    // 256 KB its start and end, for the same reason as the box.
116
    box.setDetailedText(shown.size() <= kMaxDetailChars
9 ✔
117
                            ? shown
12 ✔
118
                            : slice(shown, kMaxDetailChars / 2, false) +
15 ✔
119
                                  QStringLiteral("\n\u2026\n") +
15 ✔
120
                                  slice(shown, kMaxDetailChars / 2, true));
15 ✔
121
  }
122
  box.setStandardButtons(buttons);
64 ✔
123
  return static_cast<QMessageBox::StandardButton>(box.exec());
128 ✔
124
}
64 ✔
125

126
auto PlainMessageBox::askYes(QWidget *parent, const QString &title,
16 ✔
127
                             const QString &text) -> bool {
128
  return show(parent, QMessageBox::Question, title, text,
16 ✔
129
              QMessageBox::Yes | QMessageBox::No) == QMessageBox::Yes;
16 ✔
130
}
131

132
void PlainMessageBox::warning(QWidget *parent, const QString &title,
37 ✔
133
                              const QString &text) {
134
  show(parent, QMessageBox::Warning, title, text);
37 ✔
135
}
37 ✔
136

137
void PlainMessageBox::critical(QWidget *parent, const QString &title,
9 ✔
138
                               const QString &text) {
139
  show(parent, QMessageBox::Critical, title, text);
9 ✔
140
}
9 ✔
141

142
auto PlainMessageBox::askToGiveNewReaders(QWidget *parent, const QString &store,
4 ✔
143
                                          const QStringList &entries) -> bool {
144
  QStringList names;
4 ✔
145
  for (const QString &entry : entries) {
8 ✔
146
    names << QDir(store).relativeFilePath(entry);
8 ✔
147
  }
148
  names.sort();
149
  constexpr int kMaxListed = 15;
150
  QStringList listed = names.mid(0, kMaxListed);
4 ✔
151
  if (names.size() > kMaxListed) {
4 ✔
NEW
152
    listed << QCoreApplication::translate(
×
153
        "PlainMessageBox", "... and %n more", nullptr,
NEW
154
        static_cast<int>(names.size() - kMaxListed));
×
155
  }
156
  return askYes(
4 ✔
157
      parent,
158
      QCoreApplication::translate("PlainMessageBox",
8 ✔
159
                                  "Give these entries new readers?"),
160
      QCoreApplication::translate(
4 ✔
161
          "PlainMessageBox",
162
          "pass re-encrypts every entry here, and these would become "
163
          "readable by someone on their recipient list who cannot read them "
164
          "now:\n\n%1\n\nAn entry copied in from another folder can end up "
165
          "here this way. Go on anyway?")
166
          .arg(listed.join(QLatin1Char('\n'))));
12 ✔
167
}
168

169
auto PlainMessageBox::confirmPassRun(QWidget *parent, const QString &store,
16 ✔
170
                                     const std::function<QStringList()> &check)
171
    -> bool {
172
  QApplication::setOverrideCursor(Qt::WaitCursor);
16 ✔
173
  const QStringList entries = check();
16 ✔
174
  QApplication::restoreOverrideCursor();
16 ✔
175
  return entries.isEmpty() || askToGiveNewReaders(parent, store, entries);
32 ✔
176
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc