Skip to content

Reject null value pointers in execution-context setters - #214

Closed
shengwen0928 wants to merge 1 commit into
cloudflare:masterfrom
shengwen0928:fix/194-null-value-pointers
Closed

shengwen0928 wants to merge 1 commit into
cloudflare:masterfrom
shengwen0928:fix/194-null-value-pointers

Conversation

@shengwen0928

Copy link
Copy Markdown

Fixes #194

Five extern "C" setters in ffi/src/lib.rs read value pointers without validating them. A null JSON pointer was read from address 0 and a null IPv4 or IPv6 value was dereferenced. The two setters guarded by assert aborted on a (NULL, 0) call instead.

The setters now return false and record a last error when a non-empty value pointer is null, and a zero-length value is treated as empty. The IPv4 and IPv6 setters take a raw pointer instead of a reference so the null check is sound. The generated C header is unchanged. All five setters are wrapped in catch_panic, matching wirefilter_parse_filter and wirefilter_match.

A regression test passes NULL to each setter and checks that it returns false with a last error set, that a (NULL, 0) bytes value is accepted as empty, and that the execution context still accepts a valid value afterwards.

Verification

  • cargo test --locked -p wirefilter-ffi --lib: 15 passed
  • cargo test --locked --workspace: engine lib 175 passed, FFI lib 15 passed, C tests 23 passed, doctests 2 passed
  • cargo clippy --locked --workspace --all-targets -- -D warnings: clean apart from pre-existing unused manifest dependencies in the fuzz crates
  • cargo fmt -p wirefilter-ffi -- --check: clean

Five extern "C" setters in ffi/src/lib.rs read value pointers
without validating them. A null JSON pointer was read from address 0
and a null IPv4 or IPv6 value was dereferenced. The two setters
guarded by assert aborted on a (NULL, 0) call instead.

The setters now return false and record a last error when a non-empty
value pointer is null, and a zero-length value is treated as empty.
The IPv4 and IPv6 setters take a raw pointer instead of a reference
so the null check is sound. The generated C header is unchanged. All
five setters are wrapped in catch_panic, matching
wirefilter_parse_filter and wirefilter_match.

A regression test passes NULL to each setter and checks that it
returns false with a last error set, that a (NULL, 0) bytes value is
accepted as empty, and that the execution context still accepts a
valid value afterwards.
@marmeladema

Copy link
Copy Markdown
Collaborator

Thank you for your interest in wirefilter.

We are not likely to merge this as the ffi layer will be deleted soon and is not maintained anymore.

@shengwen0928

Copy link
Copy Markdown
Author

Understood, thank you for letting me know — and for maintaining wirefilter. I'll close this one.

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.

Five FFI value-ingestion setters have missing/inconsistent null-pointer validation — two produce a real SIGSEGV, not a panic

2 participants