Skip to content

fix call to alloca in a loop php_api_datastore #1095

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

odaysec
Copy link

@odaysec odaysec commented Jun 28, 2025

= nr_alloca(sizeof(datastore_validators[i].default_value));
nr_strcpy(default_value, datastore_validators[i].default_value);
nr_php_add_assoc_string(validated_params, key, default_value);

fixed php_api_datastore call to alloca in a loop, replace the use of nr_alloca with malloc to allocate memory on the heap. This ensures that memory is properly freed after each iteration, avoiding stack overflow risks. Specifically:

  1. Replace nr_alloca(sizeof(datastore_validators[i].default_value)) with malloc(sizeof(datastore_validators[i].default_value)).
  2. Add a call to free(default_value) after the memory is used in each iteration to prevent memory leaks.
  3. Ensure no other functionality is altered.

References

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