zig/lib/std
John Schmidt adea9a1765
std.fmt: fix out-of-bounds array write in float printing
This commit fixes an out of bounds write that can occur when
formatting certain float values. The write messes up the stack and
causes incorrect results, segfaults, or nothing at all, depending on the
optimization mode used.

The `errol` function writes the digits of the float into `buffer`
starting from index 1, leaving index 0 untouched, and returns `buffer[1..]`
and the exponent. This is because `roundToPrecision` relies on index 0 being
unused in case the rounding adds a digit (e.g rounding 999.99
to 1000.00). When this happens, pointer arithmetic is used
[here](0e6d2184ca/lib/std/fmt/errol.zig (L61-L65))
to access index 0 and put the ones digit in the right place.

However, `errol3u` contains two special cases: `errolInt` and `errolFixed`,
which return from the function early. For these two special cases
index 0 was never reserved, and the return value contains `buffer`
instead of `buffer[1..]`. This causes the pointer arithmetic in
`roundToPrecision` to write out of bounds, which in the case of
`std.fmt.formatFloatDecimal` messes up the stack and causes undefined behavior.

The fix is to move the slicing of `buffer` to `buffer[1..]` from `errol3u`
to `errol` so that both the default and the special cases operate on the sliced
buffer.
2022-01-29 12:25:25 +01:00
..
atomic allocgate: renamed getAllocator function to allocator 2021-11-30 23:32:47 +00:00
build allow expected_exit_code to be null 2022-01-24 17:29:19 +02:00
c std: Add some missing termios types to c/linux.zig and os.zig 2022-01-23 17:12:07 +01:00
compress compress: add a deflate compressor 2022-01-23 19:30:06 +01:00
crypto std: break up some long lines 2022-01-28 16:23:47 -07:00
dwarf
event allocgate: renamed getAllocator function to allocator 2021-11-30 23:32:47 +00:00
fmt std.fmt: fix out-of-bounds array write in float printing 2022-01-29 12:25:25 +01:00
fs std/fs: Support XDG_DATA_HOME 2022-01-24 17:33:38 +02:00
hash allocgate: renamed getAllocator function to allocator 2021-11-30 23:32:47 +00:00
heap stage1: deal with BPF not supporting @returnAddress() 2021-12-19 23:22:05 -08:00
io readUntilDelimiter*: read only if buffer not full 2022-01-24 17:44:26 +02:00
json allocgate: renamed getAllocator function to allocator 2021-11-30 23:32:47 +00:00
math std: add f80 bits 2022-01-28 11:45:04 -07:00
mem std.mem.Allocator: upgrade to new function pointer semantics 2022-01-26 20:02:01 -07:00
meta std lib API deprecations for the upcoming 0.9.0 release 2021-11-30 00:13:07 -07:00
net Check for isDarwin() instead of linked libc 2022-01-14 13:44:38 +01:00
os fchown: use the 32-bit uid/gid variant of the syscall on 32-bit linux targets 2022-01-27 20:27:16 +02:00
rand
special stage2: avoid inferred struct in os_version_check.zig 2022-01-26 00:48:05 -05:00
target
testing allocgate: change resize to return optional instead of error 2021-11-30 23:45:01 +00:00
Thread Fix a bug in std.Thread.Condition and add a basic Condition test. (#10538) 2022-01-11 13:04:24 -05:00
time std.time.epoch: fix issue in documentation 2021-12-16 19:08:58 -08:00
tz Support legacy TZ format, expose header struct to a potential writer 2022-01-01 12:47:08 +00:00
unicode
valgrind
x Check for isDarwin() instead of linked libc 2022-01-14 13:44:38 +01:00
zig fmt: handle doc comments on struct members 2022-01-29 12:19:31 +01:00
array_hash_map.zig Revert "MultiArrayList: Fix error when struct is 0 sized" 2022-01-24 21:29:04 -07:00
array_list.zig Preserve alignment when cloning 2022-01-27 19:35:08 +02:00
ascii.zig allocgate: std Allocator interface refactor 2021-11-30 23:32:47 +00:00
atomic.zig
base64.zig std lib API deprecations for the upcoming 0.9.0 release 2021-11-30 00:13:07 -07:00
bit_set.zig 9944: make allocator the first argument (excl. self) 2021-12-03 16:42:59 -08:00
bounded_array.zig Slice function of BoundedArray now returns slice based on self pointer 2022-01-16 01:37:37 -05:00
buf_map.zig allocgate: std Allocator interface refactor 2021-11-30 23:32:47 +00:00
buf_set.zig allocgate: std Allocator interface refactor 2021-11-30 23:32:47 +00:00
build.zig Normalize some build function names 2022-01-24 20:15:32 +02:00
builtin.zig stage2: type system treats fn ptr and body separately 2022-01-24 21:47:53 -07:00
c.zig std.c: add shm_open and shm_unlink 2022-01-17 16:56:50 +02:00
child_process.zig stage1, stage2: rename c_void to anyopaque (#10316) 2021-12-19 00:24:45 -05:00
coff.zig allocgate: std Allocator interface refactor 2021-11-30 23:32:47 +00:00
compress.zig compress: add a deflate compressor 2022-01-23 19:30:06 +01:00
comptime_string_map.zig
crypto.zig std.crypto.random: Randoms are no longer passed by reference 2022-01-25 13:00:39 -05:00
cstr.zig allocgate: std Allocator interface refactor 2021-11-30 23:32:47 +00:00
debug.zig add std.debug.todo 2022-01-27 19:42:40 +02:00
dwarf.zig allocgate: std Allocator interface refactor 2021-11-30 23:32:47 +00:00
dynamic_library.zig stage1, stage2: rename c_void to anyopaque (#10316) 2021-12-19 00:24:45 -05:00
elf.zig Rename mem.bswapAllFields to byteSwapAllFields 2022-01-28 21:03:21 -05:00
enums.zig
event.zig
fifo.zig allocgate: std Allocator interface refactor 2021-11-30 23:32:47 +00:00
fmt.zig std.fmt: fix out-of-bounds array write in float printing 2022-01-29 12:25:25 +01:00
fs.zig std.fs.rename: fix Windows implementation 2022-01-02 16:58:05 -08:00
hash.zig lint: duplicate import (#10519) 2022-01-07 00:06:06 -05:00
hash_map.zig HashMap: add removeByPtr 2022-01-24 20:29:05 +02:00
heap.zig stage1, stage2: rename c_void to anyopaque (#10316) 2021-12-19 00:24:45 -05:00
io.zig std lib API deprecations for the upcoming 0.9.0 release 2021-11-30 00:13:07 -07:00
json.zig std: add json.stringifyAlloc 2022-01-17 12:32:02 +01:00
leb128.zig
linked_list.zig
log.zig std lib API deprecations for the upcoming 0.9.0 release 2021-11-30 00:13:07 -07:00
macho.zig macho: put LC_* consts in a typed enum(u32) LC 2021-12-15 08:59:20 +01:00
math.zig std: add f80 bits 2022-01-28 11:45:04 -07:00
mem.zig Rename mem.bswapAllFields to byteSwapAllFields 2022-01-28 21:03:21 -05:00
meta.zig std: add meta.DeclEnum 2022-01-20 10:54:45 +02:00
multi_array_list.zig Revert "MultiArrayList: Fix error when struct is 0 sized" 2022-01-24 21:29:04 -07:00
net.zig Merge pull request #10576 from schmee/macos-resolve-ip 2022-01-15 00:47:12 +01:00
once.zig
os.zig std: Add some missing termios types to c/linux.zig and os.zig 2022-01-23 17:12:07 +01:00
packed_int_array.zig
pdb.zig Only check the file's length once in pdb.Msf.init 2021-12-21 17:29:23 -08:00
priority_dequeue.zig std.priority_dequeue: allow comparator to take a context parameter 2021-12-15 17:46:10 -08:00
priority_queue.zig std.priority_queue: allow comparator to take a context parameter 2021-12-15 17:46:04 -08:00
process.zig remove unnecessary self argument 2022-01-20 10:55:10 +02:00
Progress.zig Fix test label off-by-one error (#10277). 2021-12-06 12:18:41 -08:00
rand.zig stage1, stage2: rename c_void to anyopaque (#10316) 2021-12-19 00:24:45 -05:00
SemanticVersion.zig
sort.zig
start.zig fix startup procedure for async WinMain 2022-01-27 19:49:12 +02:00
start_windows_tls.zig stage1, stage2: rename c_void to anyopaque (#10316) 2021-12-19 00:24:45 -05:00
std.zig tz parsing reader interface, test thicc files, and exclude tzif 2021-12-31 17:17:49 +00:00
target.zig glibc: update default cross-compile version to 2.19 2021-12-16 03:01:13 -07:00
testing.zig stage2: implement @ctz and @clz including SIMD 2022-01-12 23:53:26 -07:00
Thread.zig Fix a bug in std.Thread.Condition and add a basic Condition test. (#10538) 2022-01-11 13:04:24 -05:00
time.zig lint: duplicate import (#10519) 2022-01-07 00:06:06 -05:00
tz.zig Rename mem.bswapAllFields to byteSwapAllFields 2022-01-28 21:03:21 -05:00
unicode.zig allocgate: std Allocator interface refactor 2021-11-30 23:32:47 +00:00
valgrind.zig lint: duplicate import (#10519) 2022-01-07 00:06:06 -05:00
wasm.zig wasm: Implement memset, and sret arguments. 2022-01-04 17:59:05 +01:00
x.zig
zig.zig allocgate: std Allocator interface refactor 2021-11-30 23:32:47 +00:00