authorgravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2022-11-08 15:45:15+01:00
committergravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2022-11-08 15:45:15+01:00
log7145064efde75aaf4711671d1f5461ea56040815
tree5fe09e7cd38f60ebc7d200468077b518d5be89b9
parent7d48cb11389f5dfe73d25e59c1038398a8ba9ca9

macho: fix parsing len of DW_FORM_string


1 files changed, 16 insertions(+), 7 deletions(-)

src/link/MachO/DwarfInfo.zig+16-7
......@@ -257,13 +257,21 @@ pub const Attribute = struct {
257257 }
258258
259259 pub fn getString(self: Attribute, ctx: DwarfInfo, cuh: CompileUnit.Header) ?[]const u8 {
260 if (self.form != dwarf.FORM.strp) return null;
261260 const debug_info = self.getDebugInfo(ctx);
262 const off = if (cuh.is_64bit)
263 mem.readIntLittle(u64, debug_info[0..8])
264 else
265 mem.readIntLittle(u32, debug_info[0..4]);
266 return ctx.getString(off);
261
262 switch (self.form) {
263 dwarf.FORM.string => {
264 return mem.sliceTo(@ptrCast([*:0]const u8, debug_info.ptr), 0);
265 },
266 dwarf.FORM.strp => {
267 const off = if (cuh.is_64bit)
268 mem.readIntLittle(u64, debug_info[0..8])
269 else
270 mem.readIntLittle(u32, debug_info[0..4]);
271 return ctx.getString(off);
272 },
273 else => return null,
274 }
267275 }
268276
269277 pub fn getConstant(self: Attribute, ctx: DwarfInfo) !?i128 {
......@@ -440,8 +448,9 @@ fn findFormSize(self: DwarfInfo, form: u64, di_off: usize, cuh: CompileUnit.Head
440448
441449 dwarf.FORM.string => {
442450 var count: usize = 0;
443 while (true) : (count += 1) {
451 while (true) {
444452 const byte = try reader.readByte();
453 count += 1;
445454 if (byte == 0x0) break;
446455 }
447456 return count;