Skip to content

Commit d7a7636

Browse files
r41k0uclaude
andcommitted
Core: Guard vmlinux struct lookup against non-class metadata
_allocate_for_attribute reached for `metadata.__name__` whenever the base symbol was not a known user struct, but `metadata` is only a struct class for struct-typed symbols. For a symbol carrying None (any plainly typed local) or a ctypes class (a `c_void_p` context parameter), that raised AttributeError instead of reporting the unsupported access. Resolve the name via getattr and fall through to the existing "struct type not found" diagnostic when there is none. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
1 parent b47063c commit d7a7636

1 file changed

Lines changed: 8 additions & 2 deletions

File tree

pythonbpf/allocation_pass.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -340,9 +340,15 @@ def _allocate_for_attribute(
340340

341341
struct_type: type = local_sym_tab[struct_var].metadata
342342
if not struct_type or struct_type not in structs_sym_tab:
343-
if VmlinuxHandlerRegistry.is_vmlinux_struct(struct_type.__name__):
343+
# `metadata` only names a struct for struct-typed symbols. For anything
344+
# else (None, an IR type, or a plain ctypes class such as a `c_void_p`
345+
# context parameter) there is no vmlinux struct name to look up, so guard
346+
# the attribute access instead of blowing up with an AttributeError.
347+
vmlinux_struct_name = getattr(struct_type, "__name__", None)
348+
if vmlinux_struct_name and VmlinuxHandlerRegistry.is_vmlinux_struct(
349+
vmlinux_struct_name
350+
):
344351
# Handle vmlinux struct field access
345-
vmlinux_struct_name = struct_type.__name__
346352
if not VmlinuxHandlerRegistry.has_field(vmlinux_struct_name, field_name):
347353
logger.error(
348354
f"Field '{field_name}' not found in vmlinux struct '{vmlinux_struct_name}'"

0 commit comments

Comments
 (0)