| author | |
| committer | |
| log | 69f46cab555edd3fda9012a237aa7f708c144bfe |
| tree | 5b0880b6d3322b241bc7d5337bd779cfce09efdc |
| parent | 452c35656ed51944e164419e545381e889b4deb2 |
The buffer `buf` contains N (= `slice_sizes.len`) slices followed by the
N null-terminated arguments. The N null-terminated arguments are stored
in the `contents` array list. Thus, `buf` size should be:
@sizeOf([]u8) * slice_sizes.len + contents_slice.len
Instead of:
@sizeOf([]u8) * slice_sizes.len + contents_slice.len + slice_sizes.len
This bug was found thanks to the gpa allocator which checks if freed
size matches allocated sizes for large allocations.1 files changed, 1 insertions(+), 2 deletions(-)
lib/std/process.zig+1-2| ... | ... | @@ -559,9 +559,8 @@ pub fn argsAlloc(allocator: mem.Allocator) ![][:0]u8 { |
| 559 | 559 | |
| 560 | 560 | const contents_slice = contents.items; |
| 561 | 561 | const slice_sizes = slice_list.items; |
| 562 | const contents_size_bytes = try math.add(usize, contents_slice.len, slice_sizes.len); | |
| 563 | 562 | const slice_list_bytes = try math.mul(usize, @sizeOf([]u8), slice_sizes.len); |
| 564 | const total_bytes = try math.add(usize, slice_list_bytes, contents_size_bytes); | |
| 563 | const total_bytes = try math.add(usize, slice_list_bytes, contents_slice.len); | |
| 565 | 564 | const buf = try allocator.alignedAlloc(u8, @alignOf([]u8), total_bytes); |
| 566 | 565 | errdefer allocator.free(buf); |
| 567 | 566 |