-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
std.os.read() can fault on Linux with empty 0-length buffer provided #13776
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
I'm putting together a PR that resolves this now (along with test). |
Reading through the documentation on this, things are a little confusing, looking at https://linux.die.net/man/3/read :
Which to me implies that we are passing through an invalid pointer which is being checked, but having read through the code, as far as I'm aware std.testing.allocator seems to be returning a valid pointer? So this is a little confusing. As const new_aligned_size = @max(len, @as(usize, 1) << @intCast(Allocator.Log2Align, log2_ptr_align));
...
const new_size_class = math.ceilPowerOfTwoAssert(usize, new_aligned_size);
const ptr = try self.allocSlot(new_size_class, ret_addr);
if (config.verbose_log) {
log.info("small alloc {d} bytes at {*}", .{ len, ptr });
}
return ptr; Which to me implies a valid slot is always being returned. So unless something else is invalidating the pointer I'm not aware of, this shouldn't be erroring. So maybe a fix isn't needed in |
Duplicate of #11604 |
Zig Version
0.11.0-dev.514+4be1bb4aa
Steps to Reproduce and Observed Behavior
This panics:
Expected Behavior
Based on how zig otherwise deals with 0 values, I would expect this case to be gracefully handled (.i.e be a no-op). Otherwise, it should be clearly documented that 0 is an invalid argument in
std.os.read()
.The text was updated successfully, but these errors were encountered: