authorgravatar for thatlemon@gmail.comLemonBoy <thatlemon@gmail.com> 2021-03-05 22:08:34+01:00
committergravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2021-03-07 14:58:45+02:00
loge47b754b28d658f05b72811207b9f953c1ab83e9
tree2f435ce3ea43c4d2f55a39cb660efef42807a28c
parent6d69a29d753de8680ff1220b8d9127e890e7d965

std: Prevent null pointer deref in mem.len{,Z}

Closes #8140

1 files changed, 8 insertions(+), 2 deletions(-)

lib/std/mem.zig+8-2
......@@ -647,7 +647,10 @@ pub fn len(value: anytype) usize {
647647 indexOfSentinel(info.child, sentinel, value)
648648 else
649649 @compileError("length of pointer with no sentinel"),
650 .C => indexOfSentinel(info.child, 0, value),
650 .C => {
651 assert(value != null);
652 return indexOfSentinel(info.child, 0, value);
653 },
651654 .Slice => value.len,
652655 },
653656 .Struct => |info| if (info.is_tuple) {
......@@ -708,7 +711,10 @@ pub fn lenZ(ptr: anytype) usize {
708711 indexOfSentinel(info.child, sentinel, ptr)
709712 else
710713 @compileError("length of pointer with no sentinel"),
711 .C => indexOfSentinel(info.child, 0, ptr),
714 .C => {
715 assert(ptr != null);
716 return indexOfSentinel(info.child, 0, ptr);
717 },
712718 .Slice => if (info.sentinel) |sentinel|
713719 indexOfSentinel(info.child, sentinel, ptr.ptr)
714720 else