|
|
00e791 |
From 344a8364cb05cdaafc43231d0f73d5217c4e118c Mon Sep 17 00:00:00 2001
|
|
|
24a050 |
From: Peter Jones <pjones@redhat.com>
|
|
|
24a050 |
Date: Tue, 12 Feb 2019 18:04:49 -0500
|
|
|
00e791 |
Subject: [PATCH 28/62] VLogError(): Avoid NULL pointer dereferences in
|
|
|
00e791 |
(V)Sprint calls
|
|
|
00e791 |
|
|
|
00e791 |
VLogError() calculates the size of format strings by using calls to
|
|
|
00e791 |
SPrint and VSPrint with a StrSize of 0 and NULL for an output buffer.
|
|
|
00e791 |
Unfortunately, this is an incorrect usage of (V)Sprint. A StrSize
|
|
|
00e791 |
of "0" is special-cased to mean "there is no limit". So, we end up
|
|
|
00e791 |
writing our string to address 0x0. This was discovered because it
|
|
|
00e791 |
causes a crash on ARM where, unlike x86, it does not necessarily
|
|
|
00e791 |
have memory mapped at 0x0.
|
|
|
00e791 |
|
|
|
00e791 |
Avoid the (V)Sprint calls altogether by using (V)PoolPrint, which
|
|
|
00e791 |
handles the size calculation and allocation for us.
|
|
|
24a050 |
|
|
|
24a050 |
Signed-off-by: Peter Jones <pjones@redhat.com>
|
|
|
00e791 |
Fixes: 25f6fd08cd26 ("try to show errors more usefully.")
|
|
|
00e791 |
[dannf: commit message ]
|
|
|
00e791 |
Signed-off-by: dann frazier <dann.frazier@canonical.com>
|
|
|
00e791 |
Upstream-commit-id: 20e731f423a
|
|
|
24a050 |
---
|
|
|
24a050 |
errlog.c | 15 +++------------
|
|
|
24a050 |
1 file changed, 3 insertions(+), 12 deletions(-)
|
|
|
24a050 |
|
|
|
24a050 |
diff --git a/errlog.c b/errlog.c
|
|
|
24a050 |
index 18be4822d53..eebb266d396 100644
|
|
|
24a050 |
--- a/errlog.c
|
|
|
24a050 |
+++ b/errlog.c
|
|
|
24a050 |
@@ -14,29 +14,20 @@ EFI_STATUS
|
|
|
24a050 |
VLogError(const char *file, int line, const char *func, CHAR16 *fmt, va_list args)
|
|
|
24a050 |
{
|
|
|
24a050 |
va_list args2;
|
|
|
24a050 |
- UINTN size = 0, size2;
|
|
|
24a050 |
CHAR16 **newerrs;
|
|
|
24a050 |
|
|
|
24a050 |
- size = SPrint(NULL, 0, L"%a:%d %a() ", file, line, func);
|
|
|
24a050 |
- va_copy(args2, args);
|
|
|
24a050 |
- size2 = VSPrint(NULL, 0, fmt, args2);
|
|
|
24a050 |
- va_end(args2);
|
|
|
24a050 |
-
|
|
|
24a050 |
newerrs = ReallocatePool(errs, (nerrs + 1) * sizeof(*errs),
|
|
|
24a050 |
(nerrs + 3) * sizeof(*errs));
|
|
|
24a050 |
if (!newerrs)
|
|
|
24a050 |
return EFI_OUT_OF_RESOURCES;
|
|
|
24a050 |
|
|
|
24a050 |
- newerrs[nerrs] = AllocatePool(size*2+2);
|
|
|
24a050 |
+ newerrs[nerrs] = PoolPrint(L"%a:%d %a() ", file, line, func);
|
|
|
24a050 |
if (!newerrs[nerrs])
|
|
|
24a050 |
return EFI_OUT_OF_RESOURCES;
|
|
|
24a050 |
- newerrs[nerrs+1] = AllocatePool(size2*2+2);
|
|
|
24a050 |
+ va_copy(args2, args);
|
|
|
24a050 |
+ newerrs[nerrs+1] = VPoolPrint(fmt, args2);
|
|
|
24a050 |
if (!newerrs[nerrs+1])
|
|
|
24a050 |
return EFI_OUT_OF_RESOURCES;
|
|
|
24a050 |
-
|
|
|
24a050 |
- SPrint(newerrs[nerrs], size*2+2, L"%a:%d %a() ", file, line, func);
|
|
|
24a050 |
- va_copy(args2, args);
|
|
|
24a050 |
- VSPrint(newerrs[nerrs+1], size2*2+2, fmt, args2);
|
|
|
24a050 |
va_end(args2);
|
|
|
24a050 |
|
|
|
24a050 |
nerrs += 2;
|
|
|
24a050 |
--
|
|
|
00e791 |
2.26.2
|
|
|
24a050 |
|