zig/lib/std
John Schmidt 5762b6d218 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-02-02 22:01:47 -07:00
..
atomic allocgate: renamed getAllocator function to allocator 2021-11-30 23:32:47 +00:00
build Add test executable builds to build.zig 2021-12-06 14:55:35 -06:00
c std: Add some missing termios types to c/linux.zig and os.zig 2022-02-02 21:23:34 -07:00
compress allocgate: std Allocator interface refactor 2021-11-30 23:32:47 +00:00
crypto std: break up some long lines 2022-02-02 22:00:55 -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-02-02 22:01:47 -07:00
fs std/fs: Support XDG_DATA_HOME 2022-02-02 21:24:40 -07: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-02-02 21:25:03 -07:00
json allocgate: renamed getAllocator function to allocator 2021-11-30 23:32:47 +00:00
math std/math: hide internal cos/tan functions 2021-12-06 01:17:01 +13:00
mem Allocator: allocBytes and reallocBytes (#10352) 2021-12-19 01:58:13 -05:00
meta std lib API deprecations for the upcoming 0.9.0 release 2021-11-30 00:13:07 -07:00
net Merge pull request #10576 from schmee/macos-resolve-ip 2022-02-02 21:12:24 -07:00
os fchown: use the 32-bit uid/gid variant of the syscall on 32-bit linux targets 2022-02-02 22:00:06 -07:00
rand Add argument for fillFn to Random.init 2021-10-29 19:20:31 -04:00
special zig test: fix test runner detection of tty 2021-12-18 23:45:32 -07: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-12 11:59:09 -07:00
time std.time.epoch: fix issue in documentation 2021-12-16 19:08:58 -08:00
unicode migrate from std.Target.current to @import("builtin").target 2021-10-04 23:48:55 -07:00
valgrind
x Merge pull request #10576 from schmee/macos-resolve-ip 2022-02-02 21:12:24 -07:00
zig fmt: handle doc comments on struct members 2022-02-02 22:01:38 -07:00
array_hash_map.zig allocgate: std Allocator interface refactor 2021-11-30 23:32:47 +00:00
array_list.zig allocgate: renamed getAllocator function to allocator 2021-11-30 23:32:47 +00:00
ascii.zig allocgate: std Allocator interface refactor 2021-11-30 23:32:47 +00:00
atomic.zig migrate from std.Target.current to @import("builtin").target 2021-10-04 23:48:55 -07:00
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 std.bounded_array: support inserting a new value at the end (#10340) 2021-12-15 20:10:34 +01: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 Merge pull request #10475 from lithdew/master 2022-02-02 21:19:18 -07:00
builtin.zig AstGen: implement @prefetch() builtin 2021-12-10 23:09:02 +01:00
c.zig Merge pull request #10576 from schmee/macos-resolve-ip 2022-02-02 21:12:24 -07: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
comptime_string_map.zig
crypto.zig std.crypto.random: Randoms are no longer passed by reference 2022-02-02 21:46:22 -07:00
cstr.zig allocgate: std Allocator interface refactor 2021-11-30 23:32:47 +00:00
debug.zig Implement segfault handler for macOS x86_64 2022-02-02 21:18:45 -07: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 Fix dead link 2021-12-31 14:19:36 -07: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-02-02 22:01:47 -07:00
fs.zig stage2: improve handling of the generated file builtin.zig 2021-12-06 23:30:18 -08:00
hash.zig
hash_map.zig std: hash_map: optimize isFree/isTombstone (#10562) 2022-01-12 11:58:24 -07: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 allocgate: renamed getAllocator function to allocator 2021-11-30 23:32:47 +00: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 lib API deprecations for the upcoming 0.9.0 release 2021-11-30 00:13:07 -07:00
mem.zig Update the documentation for std.mem.sliceTo for readability 2022-02-02 21:48:48 -07:00
meta.zig std lib API deprecations for the upcoming 0.9.0 release 2021-11-30 00:13:07 -07:00
multi_array_list.zig Merge branch 'Jarred-Sumner-patch-1' 2022-02-02 21:14:59 -07:00
net.zig Merge pull request #10576 from schmee/macos-resolve-ip 2022-02-02 21:12:24 -07:00
once.zig std.Thread.Mutex: change API to lock() and unlock() 2021-11-09 18:31:03 -07:00
os.zig std: Add some missing termios types to c/linux.zig and os.zig 2022-02-02 21:23:34 -07:00
packed_int_array.zig Better documentation, use of len field instead of function, @bitSizeOf instead of meta.bitCout 2021-10-09 03:15:34 -04:00
pdb.zig Only check the file's length once in pdb.Msf.init 2021-12-31 14:20:02 -07: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 allocgate: renamed getAllocator function to allocator 2021-11-30 23:32:47 +00: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 std.rand: Refactor Random interface 2021-10-27 16:07:48 -04:00
start.zig fix startup procedure for async WinMain 2022-02-02 21:59:47 -07:00
start_windows_tls.zig stage1, stage2: rename c_void to anyopaque (#10316) 2021-12-19 00:24:45 -05:00
std.zig migrate from std.Target.current to @import("builtin").target 2021-10-04 23:48:55 -07:00
target.zig glibc: update default cross-compile version to 2.19 2021-12-16 03:01:13 -07:00
testing.zig fix expectStringEndsWith error output. 2021-12-31 14:20:09 -07:00
Thread.zig Fix a bug in std.Thread.Condition and add a basic Condition test. (#10538) 2022-01-12 11:59:09 -07:00
time.zig migrate from std.Target.current to @import("builtin").target 2021-10-04 23:48:55 -07:00
unicode.zig allocgate: std Allocator interface refactor 2021-11-30 23:32:47 +00:00
valgrind.zig
wasm.zig allocgate: std Allocator interface refactor 2021-11-30 23:32:47 +00:00
x.zig
zig.zig allocgate: std Allocator interface refactor 2021-11-30 23:32:47 +00:00