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

Add exec integration #2361

Merged
merged 4 commits into from
Dec 29, 2023
Merged

Add exec integration #2361

merged 4 commits into from
Dec 29, 2023

Conversation

cataphract
Copy link
Contributor

@cataphract cataphract commented Nov 16, 2023

Description

Create spans for exec functions in PHP.

Related Jiras: APPSEC-11906, APPSEC-11909, APPSEC-11910, APPSEC-11911, APPSEC-11912, APPSEC-12116

Readiness checklist

  • (only for Members) Changelog has been added to the release document.
  • Tests added for this feature/bug.

Reviewer checklist

  • Appropriate labels assigned.
  • Milestone is set.
  • Changelog has been added to the release document. For community contributors the reviewer is in charge of this task.

@cataphract cataphract requested a review from a team as a code owner November 16, 2023 00:12
@cataphract cataphract force-pushed the glopes/exec-integration branch 2 times, most recently from d56c4bc to d1c3538 Compare November 16, 2023 00:25
Comment on lines 277 to 264
// clang-format off
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(register_stream, 0, 2, _IS_BOOL, 0)
ZEND_ARG_TYPE_INFO(0, stream, IS_RESOURCE, 0)
ZEND_ARG_OBJ_INFO(0, span, DDTrace\\SpanData, 0)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(proc_assoc_span, 0, 2, _IS_BOOL, 1)
ZEND_ARG_TYPE_INFO(0, proc_res, IS_RESOURCE, 0)
ZEND_ARG_OBJ_INFO(0, span, DDTrace\\SpanData, 0)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(proc_get_span, 0, 1, DDTrace\\SpanData, 0)
ZEND_ARG_TYPE_INFO(0, proc_res, IS_RESOURCE, 0)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(proc_get_pid, 0, 1, IS_LONG, 1)
ZEND_ARG_TYPE_INFO(0, proc_res, IS_RESOURCE, 0)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(test_rshutdown, 0, 0, IS_NULL, 1)
ZEND_END_ARG_INFO()

static const zend_function_entry functions[] = {
ZEND_RAW_FENTRY(NS "register_stream", PHP_FN(DDTrace_integrations_exec_register_stream), register_stream, 0)
ZEND_RAW_FENTRY(NS "proc_assoc_span", PHP_FN(DDTrace_integrations_exec_proc_assoc_span), proc_assoc_span, 0)
ZEND_RAW_FENTRY(NS "proc_get_span", PHP_FN(DDTrace_integrations_exec_proc_get_span), proc_get_span, 0)
ZEND_RAW_FENTRY(NS "proc_get_pid", PHP_FN(DDTrace_integrations_exec_proc_get_pid), proc_get_pid, 0)
ZEND_RAW_FENTRY(NS "test_rshutdown", PHP_FN(DDTrace_integrations_exec_test_rshutdown), test_rshutdown, 0)
PHP_FE_END
};
Copy link
Collaborator

@bwoebi bwoebi Nov 16, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please add the definitions to ddtrace.stub.php?
A pure testing function like exec_test_reshutdown and proc_get_pid should be proably hidden away in dd_trace_internal_fn - we're trying to be a bit tidy regarding testing functions :-)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@cataphract You moved it to the stub file, but did not regenerate the arginfo: in php-src repo, there's a build/gen_stub.php script, which needs to be run.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I put them in a different stub file.

As to moving them do dd_trace_internal_fn I don't think it's a good idea. I'd either have to duplicate logic from integrations_exec (fetching the resource type and a conditional typedef) or to export global functions in integrations_exec.c. Either way, it's a solution with less code cohesion. Also, proc_get_pid doesn't fit the signature of dd_trace_internal_fn, which returns a bool. The only disadvantage of the current solution is that are more PHP functions registered, but they are in a namespace that only has internal functions anyway.

@cataphract cataphract force-pushed the glopes/exec-integration branch 7 times, most recently from 8c99e37 to ebbf556 Compare November 20, 2023 14:41
@bwoebi bwoebi added this to the 0.95.0 milestone Nov 20, 2023
@cataphract cataphract force-pushed the glopes/exec-integration branch 3 times, most recently from ca57039 to 154e4a9 Compare November 23, 2023 13:07
@bwoebi
Copy link
Collaborator

bwoebi commented Nov 23, 2023

Can you add all internal functions to dd_install_internal_handlers()?
This is needed for a JIT workaround on 8.0 and 8.1... (crappy, but yeah)

@cataphract cataphract force-pushed the glopes/exec-integration branch 4 times, most recently from dece386 to 2529033 Compare November 24, 2023 12:29
@Anilm3 Anilm3 modified the milestones: 0.95.0, future Dec 7, 2023
Copy link
Contributor

@Anilm3 Anilm3 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm, I would like to see some feedback from @estringana and @PROFeNoM as well though, but as far as I can tell everything looks correct and following the specification.

ext/handlers_internal.c Show resolved Hide resolved
ext/integrations/exec_integration.c Outdated Show resolved Hide resolved
ext/integrations/exec_integration.c Outdated Show resolved Hide resolved
ext/integrations/exec_integration.c Show resolved Hide resolved
ext/integrations/exec_integration.c Outdated Show resolved Hide resolved
}

if ($hook->returned === -1 && isset($span->meta[Tag::EXEC_EXIT_CODE])) {
$hook->overrideReturnValue($span->meta[Tag::EXEC_EXIT_CODE]);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This clarifies things, perhaps you should document a bit better the proc_open implementation.

@github-actions github-actions bot removed this from the future milestone Dec 29, 2023
@cataphract cataphract merged commit afa2b3c into master Dec 29, 2023
610 of 612 checks passed
@cataphract cataphract deleted the glopes/exec-integration branch December 29, 2023 17:45
@github-actions github-actions bot added this to the 0.97.0 milestone Dec 29, 2023

#define NS "DDTrace\\Integrations\\Exec\\"

#if PHP_VERSION_ID <= 80000
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be <, not <=

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.

None yet

4 participants