Skip to content

[C API] Add null check in BinaryenTableGrow for missing table#8376

Open
sumleo wants to merge 2 commits intoWebAssembly:mainfrom
sumleo:fix-tablegrow-null-check
Open

[C API] Add null check in BinaryenTableGrow for missing table#8376
sumleo wants to merge 2 commits intoWebAssembly:mainfrom
sumleo:fix-tablegrow-null-check

Conversation

@sumleo
Copy link
Contributor

@sumleo sumleo commented Feb 25, 2026

Summary

  • Fix null pointer dereference in BinaryenTableGrow when the table name doesn't exist in the module
  • The convenience path where value == nullptr calls getTableOrNull(name) and immediately dereferences the result without a null check
  • Add a null check so that if the table doesn't exist, value remains nullptr and downstream code handles the error gracefully

Test plan

  • Verified the fix compiles and the diff is minimal
  • Checked no other instances of this pattern exist in binaryen-c.cpp
  • Existing c-api-kitchen-sink test continues to work (it passes a non-null value so doesn't exercise this path)

BinaryenTableGrow has a convenience path where passing value=nullptr
auto-creates a ref.null of the table's element type. However, it calls
getTableOrNull(name) and immediately dereferences the result without
checking for null. If the table name doesn't exist in the module, this
causes a null pointer dereference.

Add a null check after getTableOrNull so that if the table doesn't
exist, value remains nullptr and downstream code handles the error.
@kripken
Copy link
Member

kripken commented Feb 26, 2026

The CI error here looks like a problem on main that was fixed. Merging in latest main should fix it.

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.

2 participants