authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-09-21 21:55:41-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-09-21 21:55:41-07:00
log747440677dc58394c73235627d9016ee5f7588d8
tree1ddc55186d1741fd7a9f9088f63763ae11a8fd67
parent81b5df347a2b92566dc679fdd4e110812dfe27d0

LLVM: fix UAF when lowering debug info for structs

Gotta call the get() function inside the loop if the loop adds anything to InternPool.

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

src/codegen/llvm.zig+2-3
...@@ -2495,17 +2495,16 @@ pub const Object = struct {...@@ -2495,17 +2495,16 @@ pub const Object = struct {
2495 }2495 }
24962496
2497 const struct_type = mod.typeToStruct(ty).?;2497 const struct_type = mod.typeToStruct(ty).?;
2498 const field_types = struct_type.field_types.get(ip);
24992498
2500 var di_fields: std.ArrayListUnmanaged(*llvm.DIType) = .{};2499 var di_fields: std.ArrayListUnmanaged(*llvm.DIType) = .{};
2501 defer di_fields.deinit(gpa);2500 defer di_fields.deinit(gpa);
25022501
2503 try di_fields.ensureUnusedCapacity(gpa, field_types.len);2502 try di_fields.ensureUnusedCapacity(gpa, struct_type.field_types.len);
25042503
2505 comptime assert(struct_layout_version == 2);2504 comptime assert(struct_layout_version == 2);
2506 var it = struct_type.iterateRuntimeOrder(ip);2505 var it = struct_type.iterateRuntimeOrder(ip);
2507 while (it.next()) |field_index| {2506 while (it.next()) |field_index| {
2508 const field_ty = field_types[field_index].toType();2507 const field_ty = struct_type.field_types.get(ip)[field_index].toType();
2509 if (!field_ty.hasRuntimeBitsIgnoreComptime(mod)) continue;2508 if (!field_ty.hasRuntimeBitsIgnoreComptime(mod)) continue;
2510 const field_size = field_ty.abiSize(mod);2509 const field_size = field_ty.abiSize(mod);
2511 const field_align = mod.structFieldAlignment(2510 const field_align = mod.structFieldAlignment(