Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PHP.wasm: fix stack overflow in wasm_set_request_body #993

Merged
merged 4 commits into from
Feb 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion packages/php-wasm/compile/php/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -772,6 +772,10 @@ RUN set -euxo pipefail; \
mkdir -p /build/output; \
source /root/emsdk/emsdk_env.sh; \
export EXPORTED_FUNCTIONS=$'["_exit", \n\
"UTF8ToString", \n\
"stringToUTF8", \n\
"lengthBytesUTF8", \n\
"FS", \n\
"_wasm_set_sapi_name", \n\
"_php_wasm_init", \n\
"_phpwasm_destroy_uploaded_files_hash", \n\
Expand Down Expand Up @@ -814,7 +818,7 @@ RUN set -euxo pipefail; \
$(cat /root/.emcc-php-wasm-flags) \
-o /build/output/php.js \
-s EXPORTED_FUNCTIONS="$EXPORTED_FUNCTIONS" \
-s EXTRA_EXPORTED_RUNTIME_METHODS='["ccall", "UTF8ToString", "lengthBytesUTF8", "FS", "PROXYFS"]' \
-s EXTRA_EXPORTED_RUNTIME_METHODS='["ccall", "PROXYFS"]' \
-s INITIAL_MEMORY=1024MB \
-s ALLOW_MEMORY_GROWTH=1 \
-s ASSERTIONS=0 \
Expand Down
20 changes: 20 additions & 0 deletions packages/php-wasm/compile/php/esm-suffix.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,26 @@ PHPLoader['removeRunDependency'] = function (...args) {
}
}

/**
* Other exports live in the Dockerfile in:
*
* * EXTRA_EXPORTED_RUNTIME_METHODS
* * EXPORTED_FUNCTIONS
*
* These exports, however, live in here because:
*
* * Listing them in EXTRA_EXPORTED_RUNTIME_METHODS doesn't actually
* export them. This could be a bug in Emscripten or a consequence of
* that option being deprecated.
* * Listing them in EXPORTED_FUNCTIONS works, but they are overridden
* on every `BasePHP.run()` call. This is a problem because we want to
* spy on these calls in some unit tests.
*
* Therefore, we export them here.
*/
PHPLoader['malloc'] = _malloc;
PHPLoader['free'] = _free;

return PHPLoader;

// Close the opening bracket from esm-prefix.js:
Expand Down
8 changes: 2 additions & 6 deletions packages/php-wasm/compile/php/php_wasm.c
Original file line number Diff line number Diff line change
Expand Up @@ -695,10 +695,6 @@ void wasm_destroy_server_context()
{
free(wasm_server_context->content_type);
}
if (wasm_server_context->request_body != NULL)
{
free(wasm_server_context->request_body);
}
if (wasm_server_context->cookies != NULL)
{
free(wasm_server_context->cookies);
Expand Down Expand Up @@ -876,11 +872,11 @@ void wasm_set_content_type(char *content_type)
* ----------------------------
* Sets the request body for the next request.
*
* request_body: the request body, e.g. "name=John&age=30"
* request_body: the Heap pointer to the request body, e.g. "name=John&age=30"
*/
void wasm_set_request_body(char *request_body)
{
wasm_server_context->request_body = strdup(request_body);
wasm_server_context->request_body = request_body;
}

/**
Expand Down
Loading
Loading