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 {
24952495 }
24962496
24972497 const struct_type = mod.typeToStruct(ty).?;
2498 const field_types = struct_type.field_types.get(ip);
24992498
25002499 var di_fields: std.ArrayListUnmanaged(*llvm.DIType) = .{};
25012500 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
25052504 comptime assert(struct_layout_version == 2);
25062505 var it = struct_type.iterateRuntimeOrder(ip);
25072506 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();
25092508 if (!field_ty.hasRuntimeBitsIgnoreComptime(mod)) continue;
25102509 const field_size = field_ty.abiSize(mod);
25112510 const field_align = mod.structFieldAlignment(