Skip to content

Add NULL check after struct_field_read_integer calls#12

Open
hobostay wants to merge 1 commit intomicrosoft:publicfrom
hobostay:fix-struct-field-null-check
Open

Add NULL check after struct_field_read_integer calls#12
hobostay wants to merge 1 commit intomicrosoft:publicfrom
hobostay:fix-struct-field-null-check

Conversation

@hobostay
Copy link
Copy Markdown

@hobostay hobostay commented May 4, 2026

Summary

  • Add NULL pointer checks in struct_field_get_unsigned_int and struct_field_get_signed_int macros in src/0xc/std/struct.h

Details

The macros struct_field_get_unsigned_int and struct_field_get_signed_int both call struct_field_read_integer(), which can return NULL when struct_field_get_untyped returns NULL (i.e., when the field is out of bounds of the provided memory buffer).

Both macros currently dereference the result without checking for NULL:

iv_0xc = struct_field_read_integer((SF), (P), (L), &ivmem_0xc);
// iv_0xc may be NULL here!
switch ((SF)->sf_size) {
case sizeof(uint8_t):
    v_0xc = iv_0xc->iv_int8.vu;  // NULL dereference

This adds a NULL check with a descriptive panic message to prevent undefined behavior from a NULL pointer dereference.

Test plan

  • Existing test suite passes (make test)
  • The change is defensive — it adds a check that triggers only when bounds-checking fails

🤖 Generated with Claude Code

The macros struct_field_get_unsigned_int and struct_field_get_signed_int
call struct_field_read_integer which can return NULL when the field is
out of bounds of the provided memory. Add a NULL check to prevent
undefined behavior from dereferencing a NULL pointer.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant