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 {...@@ -257,13 +257,21 @@ pub const Attribute = struct {
257 }257 }
258258
259 pub fn getString(self: Attribute, ctx: DwarfInfo, cuh: CompileUnit.Header) ?[]const u8 {259 pub fn getString(self: Attribute, ctx: DwarfInfo, cuh: CompileUnit.Header) ?[]const u8 {
260 if (self.form != dwarf.FORM.strp) return null;
261 const debug_info = self.getDebugInfo(ctx);260 const debug_info = self.getDebugInfo(ctx);
262 const off = if (cuh.is_64bit)261
263 mem.readIntLittle(u64, debug_info[0..8])262 switch (self.form) {
264 else263 dwarf.FORM.string => {
265 mem.readIntLittle(u32, debug_info[0..4]);264 return mem.sliceTo(@ptrCast([*:0]const u8, debug_info.ptr), 0);
266 return ctx.getString(off);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 }
267 }275 }
268276
269 pub fn getConstant(self: Attribute, ctx: DwarfInfo) !?i128 {277 pub fn getConstant(self: Attribute, ctx: DwarfInfo) !?i128 {
...@@ -440,8 +448,9 @@ fn findFormSize(self: DwarfInfo, form: u64, di_off: usize, cuh: CompileUnit.Head...@@ -440,8 +448,9 @@ fn findFormSize(self: DwarfInfo, form: u64, di_off: usize, cuh: CompileUnit.Head
440448
441 dwarf.FORM.string => {449 dwarf.FORM.string => {
442 var count: usize = 0;450 var count: usize = 0;
443 while (true) : (count += 1) {451 while (true) {
444 const byte = try reader.readByte();452 const byte = try reader.readByte();
453 count += 1;
445 if (byte == 0x0) break;454 if (byte == 0x0) break;
446 }455 }
447 return count;456 return count;