Skip to content

fix: guard missing embedding environment variables - #369

Open
philippedev101 wants to merge 1 commit into
bytecodealliance:mainfrom
philippedev101:fix/embedding-getenv-checks
Open

philippedev101 wants to merge 1 commit into
bytecodealliance:mainfrom
philippedev101:fix/embedding-getenv-checks

Conversation

@philippedev101

Copy link
Copy Markdown
Contributor

Unset Wizer environment variables currently trigger null-pointer dereferences or atoi(nullptr) UB in embedding/embedding.cpp. With these guards, omitting optional flags works cleanly, missing binding metadata returns structured initialization errors instead of trapping, and the embedding passes Clang Static Analyzer with zero warnings.

In componentize_initialize(), unset DEBUG and FEATURE_CLOCKS now leave those features disabled. Missing EXPORT_CNT or EXPORT*_NAME returns FnList, and missing EXPORT*_ARGS, EXPORT*_RET, or EXPORT*_RETSIZE returns TypeParse. In install(), missing SOURCE_NAME, IMPORT_CNT, IMPORT*_NAME, or IMPORT*_ARGCNT now returns false.

In call(), the scalar argument path now asserts MOZ_RELEASE_ASSERT(argptr) before reading the buffer, matching the nullability assumption on line 186.

Checked with clang++ --analyze (0 diagnostics), Wizer runs omitting each of the eleven env vars, and npm run test:release (79 passed, 1 skipped).

Check getenv() results in embedding/embedding.cpp before passing them to atoi(), std::string(), JS_GetProperty(), or indexing arg_tys[0]. Optional DEBUG and FEATURE_CLOCKS flags now default to disabled when unset, missing Wizer binding metadata reports FnList, TypeParse, or install() failure instead of dereferencing null pointers, and call() asserts argptr is non-null before decoding scalar arguments.
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