Arvind Sankar
d850a2ff91
efi/printf: Add support for wchar_t (UTF-16)
...
Support %lc and %ls to output UTF-16 strings (converted to UTF-8).
Signed-off-by: Arvind Sankar <nivedita@alum.mit.edu >
Link: https://lore.kernel.org/r/20200518190716.751506-21-nivedita@alum.mit.edu
Signed-off-by: Ard Biesheuvel <ardb@kernel.org >
2020-05-20 19:09:20 +02:00
Arvind Sankar
8fb331e10b
efi/printf: Turn vsprintf into vsnprintf
...
Implement vsnprintf instead of vsprintf to avoid the possibility of a
buffer overflow.
Signed-off-by: Arvind Sankar <nivedita@alum.mit.edu >
Link: https://lore.kernel.org/r/20200518190716.751506-17-nivedita@alum.mit.edu
Signed-off-by: Ard Biesheuvel <ardb@kernel.org >
2020-05-19 10:32:04 +02:00
Arvind Sankar
f97ca2c816
efi/printf: Abort on invalid format
...
If we get an invalid conversion specifier, bail out instead of trying to
fix it up. The format string likely has a typo or assumed we support
something that we don't, in either case the remaining arguments won't
match up with the remaining format string.
Signed-off-by: Arvind Sankar <nivedita@alum.mit.edu >
Link: https://lore.kernel.org/r/20200518190716.751506-16-nivedita@alum.mit.edu
Signed-off-by: Ard Biesheuvel <ardb@kernel.org >
2020-05-19 10:32:04 +02:00
Arvind Sankar
6c4bcd8a46
efi/printf: Refactor code to consolidate padding and output
...
Consolidate the actual output of the formatted text into one place.
Fix a couple of edge cases:
1. If 0 is printed with a precision of 0, the printf specification says
that nothing should be output, with one exception (2b).
2. The specification for octal alternate format (%#o) adds the leading
zero not as a prefix as the 0x for hexadecimal is, but by increasing
the precision if necessary to add the zero. This means that
a. %#.2o turns 8 into "010", but 1 into "01" rather than "001".
b. %#.o prints 0 as "0" rather than "", unlike the situation for
decimal, hexadecimal and regular octal format, which all output an
empty string.
Reduce the space allocated for printing a number to the maximum actually
required (22 bytes for a 64-bit number in octal), instead of the 66
bytes previously allocated.
Signed-off-by: Arvind Sankar <nivedita@alum.mit.edu >
Link: https://lore.kernel.org/r/20200518190716.751506-15-nivedita@alum.mit.edu
Signed-off-by: Ard Biesheuvel <ardb@kernel.org >
2020-05-19 10:32:03 +02:00
Arvind Sankar
fb031937a8
efi/printf: Handle null string input
...
Print "(null)" for 's' if the input is a NULL pointer.
Signed-off-by: Arvind Sankar <nivedita@alum.mit.edu >
Link: https://lore.kernel.org/r/20200518190716.751506-14-nivedita@alum.mit.edu
Signed-off-by: Ard Biesheuvel <ardb@kernel.org >
2020-05-19 10:31:50 +02:00
Arvind Sankar
dec6119952
efi/printf: Factor out integer argument retrieval
...
Factor out the code to get the correct type of numeric argument into a
helper function.
Signed-off-by: Arvind Sankar <nivedita@alum.mit.edu >
Link: https://lore.kernel.org/r/20200518190716.751506-13-nivedita@alum.mit.edu
Signed-off-by: Ard Biesheuvel <ardb@kernel.org >
2020-05-19 10:31:50 +02:00
Arvind Sankar
3fbcf75bb4
efi/printf: Factor out width/precision parsing
...
Factor out the width/precision parsing into a helper function.
Signed-off-by: Arvind Sankar <nivedita@alum.mit.edu >
Link: https://lore.kernel.org/r/20200518190716.751506-12-nivedita@alum.mit.edu
Signed-off-by: Ard Biesheuvel <ardb@kernel.org >
2020-05-19 10:31:48 +02:00
Arvind Sankar
7c30fd7916
efi/printf: Merge 'p' with the integer formats
...
Treat 'p' as a hexadecimal integer with precision equal to the number of
digits in void *.
Signed-off-by: Arvind Sankar <nivedita@alum.mit.edu >
Link: https://lore.kernel.org/r/20200518190716.751506-11-nivedita@alum.mit.edu
Signed-off-by: Ard Biesheuvel <ardb@kernel.org >
2020-05-19 10:31:25 +02:00
Arvind Sankar
77e48db04a
efi/printf: Fix minor bug in precision handling
...
A negative precision should be ignored completely, and the presence of a
valid precision should turn off the 0 flag.
Signed-off-by: Arvind Sankar <nivedita@alum.mit.edu >
Link: https://lore.kernel.org/r/20200518190716.751506-10-nivedita@alum.mit.edu
Signed-off-by: Ard Biesheuvel <ardb@kernel.org >
2020-05-19 10:31:25 +02:00
Arvind Sankar
3b8350959c
efi/printf: Factor out flags parsing and handle '%' earlier
...
Move flags parsing code out into a helper function.
The '%%' case can be handled up front: it is not allowed to have flags,
width etc.
Signed-off-by: Arvind Sankar <nivedita@alum.mit.edu >
Link: https://lore.kernel.org/r/20200518190716.751506-9-nivedita@alum.mit.edu
Signed-off-by: Ard Biesheuvel <ardb@kernel.org >
2020-05-19 10:31:25 +02:00
Arvind Sankar
ce5e3f909f
efi/printf: Add 64-bit and 8-bit integer support
...
Support 'll' qualifier for long long by copying the decimal printing
code from lib/vsprintf.c. For simplicity, the 32-bit code is used on
64-bit architectures as well.
Support 'hh' qualifier for signed/unsigned char type integers.
Signed-off-by: Arvind Sankar <nivedita@alum.mit.edu >
Link: https://lore.kernel.org/r/20200518190716.751506-8-nivedita@alum.mit.edu
Signed-off-by: Ard Biesheuvel <ardb@kernel.org >
2020-05-19 10:31:24 +02:00
Arvind Sankar
29a2806653
efi/printf: Drop %n format and L qualifier
...
%n is unused and deprecated.
The L qualifer is parsed but not actually implemented.
Signed-off-by: Arvind Sankar <nivedita@alum.mit.edu >
Link: https://lore.kernel.org/r/20200518190716.751506-7-nivedita@alum.mit.edu
Signed-off-by: Ard Biesheuvel <ardb@kernel.org >
2020-05-19 10:30:52 +02:00
Arvind Sankar
2c7d1e30e5
efi/libstub: Add a basic printf implementation
...
Copy vsprintf from arch/x86/boot/printf.c to get a simple printf
implementation.
Signed-off-by: Arvind Sankar <nivedita@alum.mit.edu >
Link: https://lore.kernel.org/r/20200518190716.751506-5-nivedita@alum.mit.edu
[ardb: add some missing braces in if...else clauses]
Signed-off-by: Ard Biesheuvel <ardb@kernel.org >
2020-05-19 10:30:31 +02:00