Skip to content

Commit 547522c

Browse files
committed
Merge remote-tracking branch 'remotes/armbru/tags/pull-error-2020-04-04' into staging
Error reporting patches for 2020-04-04 # gpg: Signature made Sat 04 Apr 2020 13:19:40 BST # gpg: using RSA key 354BC8B3D7EB2A6B68674E5F3870B400EB918653 # gpg: issuer "[email protected]" # gpg: Good signature from "Markus Armbruster <[email protected]>" [full] # gpg: aka "Markus Armbruster <[email protected]>" [full] # Primary key fingerprint: 354B C8B3 D7EB 2A6B 6867 4E5F 3870 B400 EB91 8653 * remotes/armbru/tags/pull-error-2020-04-04: qga/commands-posix: fix use after free of local_err dump/win_dump: fix use after free of err scripts/coccinelle: add error-use-after-free.cocci Signed-off-by: Peter Maydell <[email protected]>
2 parents 146aa0f + 6a4a385 commit 547522c

File tree

4 files changed

+61
-3
lines changed

4 files changed

+61
-3
lines changed

MAINTAINERS

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2053,6 +2053,11 @@ F: include/qemu/error-report.h
20532053
F: qapi/error.json
20542054
F: util/error.c
20552055
F: util/qemu-error.c
2056+
F: scripts/coccinelle/err-bad-newline.cocci
2057+
F: scripts/coccinelle/error-use-after-free.cocci
2058+
F: scripts/coccinelle/error_propagate_null.cocci
2059+
F: scripts/coccinelle/remove_local_err.cocci
2060+
F: scripts/coccinelle/use-error_fatal.cocci
20562061

20572062
GDB stub
20582063
M: Alex Bennée <[email protected]>

dump/win_dump.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -304,13 +304,11 @@ static void restore_context(WinDumpHeader64 *h,
304304
struct saved_context *saved_ctx)
305305
{
306306
int i;
307-
Error *err = NULL;
308307

309308
for (i = 0; i < h->NumberProcessors; i++) {
310309
if (cpu_memory_rw_debug(first_cpu, saved_ctx[i].addr,
311310
(uint8_t *)&saved_ctx[i].ctx, sizeof(WinContext), 1)) {
312-
error_setg(&err, "win-dump: failed to restore CPU #%d context", i);
313-
warn_report_err(err);
311+
warn_report("win-dump: failed to restore CPU #%d context", i);
314312
}
315313
}
316314
}

qga/commands-posix.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1773,6 +1773,7 @@ static void guest_suspend(SuspendMode mode, Error **errp)
17731773
}
17741774

17751775
error_free(local_err);
1776+
local_err = NULL;
17761777

17771778
if (pmutils_supports_mode(mode, &local_err)) {
17781779
mode_supported = true;
@@ -1784,13 +1785,15 @@ static void guest_suspend(SuspendMode mode, Error **errp)
17841785
}
17851786

17861787
error_free(local_err);
1788+
local_err = NULL;
17871789

17881790
if (linux_sys_state_supports_mode(mode, &local_err)) {
17891791
mode_supported = true;
17901792
linux_sys_state_suspend(mode, &local_err);
17911793
}
17921794

17931795
if (!mode_supported) {
1796+
error_free(local_err);
17941797
error_setg(errp,
17951798
"the requested suspend mode is not supported by the guest");
17961799
} else {
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
// Find and fix trivial use-after-free of Error objects
2+
//
3+
// Copyright (c) 2020 Virtuozzo International GmbH.
4+
//
5+
// This program is free software; you can redistribute it and/or
6+
// modify it under the terms of the GNU General Public License as
7+
// published by the Free Software Foundation; either version 2 of the
8+
// License, or (at your option) any later version.
9+
//
10+
// This program is distributed in the hope that it will be useful,
11+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
// GNU General Public License for more details.
14+
//
15+
// You should have received a copy of the GNU General Public License
16+
// along with this program. If not, see
17+
// <http://www.gnu.org/licenses/>.
18+
//
19+
// How to use:
20+
// spatch --sp-file scripts/coccinelle/error-use-after-free.cocci \
21+
// --macro-file scripts/cocci-macro-file.h --in-place \
22+
// --no-show-diff ( FILES... | --use-gitgrep . )
23+
24+
@ exists@
25+
identifier fn, fn2;
26+
expression err;
27+
@@
28+
29+
fn(...)
30+
{
31+
<...
32+
(
33+
error_free(err);
34+
+ err = NULL;
35+
|
36+
error_report_err(err);
37+
+ err = NULL;
38+
|
39+
error_reportf_err(err, ...);
40+
+ err = NULL;
41+
|
42+
warn_report_err(err);
43+
+ err = NULL;
44+
|
45+
warn_reportf_err(err, ...);
46+
+ err = NULL;
47+
)
48+
... when != err = NULL
49+
when != exit(...)
50+
fn2(..., err, ...)
51+
...>
52+
}

0 commit comments

Comments
 (0)