diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2023-11-01 06:33:40 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-11-01 06:33:40 -0400 |
| commit | 725f765c376dda291d3d5afe5446221a97c189f7 (patch) | |
| tree | d2c1d77794ba13140aa4a3f0303d56bbec2bd27f /lib/std/debug.zig | |
| parent | 46062f1c13d8ee9eebf49806660c2271f2acc613 (diff) | |
| parent | 13b1e10b8f3d8df92417999ed972e5f682c82a46 (diff) | |
| download | zig-725f765c376dda291d3d5afe5446221a97c189f7.tar.gz zig-725f765c376dda291d3d5afe5446221a97c189f7.zip | |
Merge pull request #17802 from jacobly0/read-write-int
mem: fix UB in `readInt`/`writeInt` and delete variants
Diffstat (limited to 'lib/std/debug.zig')
| -rw-r--r-- | lib/std/debug.zig | 16 |
1 files changed, 8 insertions, 8 deletions
diff --git a/lib/std/debug.zig b/lib/std/debug.zig index 5302105fe9..9247ab4047 100644 --- a/lib/std/debug.zig +++ b/lib/std/debug.zig @@ -1098,8 +1098,8 @@ pub fn readElfDebugInfo( if (hdr.e_ident[elf.EI_VERSION] != 1) return error.InvalidElfVersion; const endian: std.builtin.Endian = switch (hdr.e_ident[elf.EI_DATA]) { - elf.ELFDATA2LSB => .Little, - elf.ELFDATA2MSB => .Big, + elf.ELFDATA2LSB => .little, + elf.ELFDATA2MSB => .big, else => return error.InvalidElfEndian, }; assert(endian == native_endian); // this is our own debug info @@ -1135,8 +1135,8 @@ pub fn readElfDebugInfo( const gnu_debuglink = try chopSlice(mapped_mem, shdr.sh_offset, shdr.sh_size); const debug_filename = mem.sliceTo(@as([*:0]const u8, @ptrCast(gnu_debuglink.ptr)), 0); const crc_offset = mem.alignForward(usize, @intFromPtr(&debug_filename[debug_filename.len]) + 1, 4) - @intFromPtr(gnu_debuglink.ptr); - const crc_bytes = gnu_debuglink[crc_offset .. crc_offset + 4]; - separate_debug_crc = mem.readIntSliceNative(u32, crc_bytes); + const crc_bytes = gnu_debuglink[crc_offset..][0..4]; + separate_debug_crc = mem.readInt(u32, crc_bytes, native_endian); separate_debug_filename = debug_filename; continue; } @@ -1868,10 +1868,10 @@ pub const DebugInfo = struct { elf.PT_NOTE => { // Look for .note.gnu.build-id const note_bytes = @as([*]const u8, @ptrFromInt(info.dlpi_addr + phdr.p_vaddr))[0..phdr.p_memsz]; - const name_size = mem.readIntSliceNative(u32, note_bytes[0..4]); + const name_size = mem.readInt(u32, note_bytes[0..4], native_endian); if (name_size != 4) continue; - const desc_size = mem.readIntSliceNative(u32, note_bytes[4..8]); - const note_type = mem.readIntSliceNative(u32, note_bytes[8..12]); + const desc_size = mem.readInt(u32, note_bytes[4..8], native_endian); + const note_type = mem.readInt(u32, note_bytes[8..12], native_endian); if (note_type != elf.NT_GNU_BUILD_ID) continue; if (!mem.eql(u8, "GNU\x00", note_bytes[12..16])) continue; context.build_id = note_bytes[16..][0..desc_size]; @@ -2040,7 +2040,7 @@ pub const ModuleDebugInfo = switch (native_os) { if (missing_debug_info) return error.MissingDebugInfo; var di = DW.DwarfInfo{ - .endian = .Little, + .endian = .little, .sections = sections, .is_macho = true, }; |
