contrast-agent 5.3.0 → 6.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.simplecov +1 -1
- data/Rakefile +1 -1
- data/ext/build_funchook.rb +3 -3
- data/ext/cs__assess_array/cs__assess_array.c +7 -0
- data/ext/cs__assess_basic_object/cs__assess_basic_object.c +24 -6
- data/ext/cs__assess_fiber_track/cs__assess_fiber_track.c +1 -1
- data/ext/cs__assess_hash/cs__assess_hash.c +3 -4
- data/ext/cs__assess_kernel/cs__assess_kernel.c +1 -2
- data/ext/cs__assess_marshal_module/cs__assess_marshal_module.c +26 -12
- data/ext/cs__assess_module/cs__assess_module.c +1 -1
- data/ext/cs__assess_regexp/cs__assess_regexp.c +15 -2
- data/ext/cs__assess_regexp/cs__assess_regexp.h +2 -0
- data/ext/cs__assess_string/cs__assess_string.c +21 -1
- data/ext/cs__assess_test/cs__assess_test.h +9 -0
- data/ext/cs__assess_test/cs__assess_tests.c +22 -0
- data/ext/cs__assess_test/extconf.rb +5 -0
- data/ext/cs__common/cs__common.c +113 -11
- data/ext/cs__common/cs__common.h +29 -5
- data/ext/cs__contrast_patch/cs__contrast_patch.c +55 -44
- data/ext/cs__os_information/cs__os_information.c +13 -10
- data/ext/cs__scope/cs__scope.c +146 -97
- data/ext/cs__tests/cs__tests.c +12 -0
- data/ext/cs__tests/cs__tests.h +3 -0
- data/ext/cs__tests/extconf.rb +5 -0
- data/ext/extconf_common.rb +1 -1
- data/lib/contrast/agent/assess/contrast_object.rb +16 -16
- data/lib/contrast/agent/assess/events/source_event.rb +17 -19
- data/lib/contrast/agent/assess/finalizers/hash.rb +4 -2
- data/lib/contrast/agent/assess/policy/policy.rb +9 -10
- data/lib/contrast/agent/assess/policy/policy_node.rb +58 -36
- data/lib/contrast/agent/assess/policy/policy_node_utils.rb +51 -0
- data/lib/contrast/agent/assess/policy/policy_scanner.rb +2 -16
- data/lib/contrast/agent/assess/policy/preshift.rb +8 -2
- data/lib/contrast/agent/assess/policy/propagation_method.rb +48 -14
- data/lib/contrast/agent/assess/policy/propagation_node.rb +2 -3
- data/lib/contrast/agent/assess/policy/propagator/base.rb +1 -1
- data/lib/contrast/agent/assess/policy/propagator/buffer.rb +119 -0
- data/lib/contrast/agent/assess/policy/propagator/database_write.rb +1 -1
- data/lib/contrast/agent/assess/policy/propagator/keep.rb +19 -4
- data/lib/contrast/agent/assess/policy/propagator/remove.rb +18 -2
- data/lib/contrast/agent/assess/policy/propagator/splat.rb +17 -3
- data/lib/contrast/agent/assess/policy/propagator/split.rb +17 -21
- data/lib/contrast/agent/assess/policy/propagator/substitution.rb +1 -1
- data/lib/contrast/agent/assess/policy/propagator/substitution_utils.rb +1 -1
- data/lib/contrast/agent/assess/policy/propagator/trim.rb +2 -2
- data/lib/contrast/agent/assess/policy/propagator.rb +1 -0
- data/lib/contrast/agent/assess/policy/source_method.rb +7 -7
- data/lib/contrast/agent/assess/policy/source_node.rb +1 -1
- data/lib/contrast/agent/assess/policy/trigger_method.rb +11 -17
- data/lib/contrast/agent/assess/policy/trigger_node.rb +16 -16
- data/lib/contrast/agent/assess/policy/trigger_validation/redos_validator.rb +1 -1
- data/lib/contrast/agent/assess/property/evented.rb +2 -2
- data/lib/contrast/agent/assess/property/tagged.rb +3 -3
- data/lib/contrast/agent/assess/rule/provider/hardcoded_key.rb +6 -8
- data/lib/contrast/agent/assess/rule/provider/hardcoded_password.rb +6 -7
- data/lib/contrast/agent/assess/rule/provider/hardcoded_value_rule.rb +12 -7
- data/lib/contrast/agent/assess/rule/response/auto_complete_rule.rb +1 -1
- data/lib/contrast/agent/assess/rule/response/base_rule.rb +13 -6
- data/lib/contrast/agent/assess/rule/response/body_rule.rb +3 -3
- data/lib/contrast/agent/assess/rule/response/cache_control_header_rule.rb +66 -43
- data/lib/contrast/agent/assess/rule/response/click_jacking_header_rule.rb +4 -4
- data/lib/contrast/agent/assess/rule/response/csp_header_insecure_rule.rb +6 -6
- data/lib/contrast/agent/assess/rule/response/csp_header_missing_rule.rb +4 -4
- data/lib/contrast/agent/assess/rule/response/hsts_header_rule.rb +4 -4
- data/lib/contrast/agent/assess/rule/response/parameters_pollution_rule.rb +1 -1
- data/lib/contrast/agent/assess/rule/response/x_content_type_header_rule.rb +4 -4
- data/lib/contrast/agent/assess/rule/response/x_xss_protection_header_rule.rb +3 -4
- data/lib/contrast/agent/assess/tag.rb +13 -14
- data/lib/contrast/agent/at_exit_hook.rb +12 -1
- data/lib/contrast/agent/deadzone/policy/deadzone_node.rb +0 -7
- data/lib/contrast/agent/deadzone/policy/policy.rb +0 -6
- data/lib/contrast/agent/exclusion_matcher.rb +3 -3
- data/lib/contrast/agent/inventory/database_config.rb +10 -3
- data/lib/contrast/agent/middleware.rb +10 -5
- data/lib/contrast/agent/patching/policy/after_load_patch.rb +3 -5
- data/lib/contrast/agent/patching/policy/after_load_patcher.rb +2 -2
- data/lib/contrast/agent/patching/policy/method_policy_extend.rb +4 -4
- data/lib/contrast/agent/patching/policy/patch.rb +20 -19
- data/lib/contrast/agent/patching/policy/patch_status.rb +10 -3
- data/lib/contrast/agent/patching/policy/patcher.rb +4 -4
- data/lib/contrast/agent/patching/policy/policy.rb +13 -15
- data/lib/contrast/agent/patching/policy/policy_node.rb +32 -21
- data/lib/contrast/agent/patching/policy/trigger_node.rb +1 -1
- data/lib/contrast/agent/protect/exploitable_collection.rb +38 -0
- data/lib/contrast/agent/protect/input_analyzer/input_analyzer.rb +132 -75
- data/lib/contrast/agent/protect/policy/applies_no_sqli_rule.rb +4 -3
- data/lib/contrast/agent/protect/policy/applies_path_traversal_rule.rb +3 -3
- data/lib/contrast/agent/protect/policy/applies_xxe_rule.rb +1 -1
- data/lib/contrast/agent/protect/policy/rule_applicator.rb +4 -4
- data/lib/contrast/agent/protect/rule/base.rb +53 -9
- data/lib/contrast/agent/protect/rule/base_service.rb +31 -12
- data/lib/contrast/agent/protect/rule/cmd_injection.rb +23 -3
- data/lib/contrast/agent/protect/rule/cmdi/cmdi_input_classification.rb +83 -0
- data/lib/contrast/agent/protect/rule/cmdi/cmdi_worth_watching.rb +64 -0
- data/lib/contrast/agent/protect/rule/default_scanner.rb +2 -1
- data/lib/contrast/agent/protect/rule/deserialization.rb +18 -7
- data/lib/contrast/agent/protect/rule/http_method_tampering/http_method_tampering_input_classification.rb +96 -0
- data/lib/contrast/agent/protect/rule/http_method_tampering.rb +72 -46
- data/lib/contrast/agent/protect/rule/no_sqli/no_sqli_input_classification.rb +231 -0
- data/lib/contrast/agent/protect/rule/no_sqli.rb +28 -2
- data/lib/contrast/agent/protect/rule/path_traversal.rb +13 -3
- data/lib/contrast/agent/protect/rule/sqli/sqli_input_classification.rb +18 -54
- data/lib/contrast/agent/protect/rule/sqli/sqli_worth_watching.rb +2 -5
- data/lib/contrast/agent/protect/rule/sqli.rb +16 -23
- data/lib/contrast/agent/protect/rule/unsafe_file_upload/unsafe_file_upload_input_classification.rb +82 -0
- data/lib/contrast/agent/protect/rule/unsafe_file_upload/unsafe_file_upload_matcher.rb +45 -0
- data/lib/contrast/agent/protect/rule/unsafe_file_upload.rb +42 -0
- data/lib/contrast/agent/protect/rule/xss.rb +17 -0
- data/lib/contrast/agent/protect/rule/xxe/entity_wrapper.rb +14 -13
- data/lib/contrast/agent/protect/rule/xxe.rb +25 -3
- data/lib/contrast/agent/reaction_processor.rb +1 -1
- data/lib/contrast/agent/reporting/attack_result/attack_result.rb +63 -0
- data/lib/contrast/agent/reporting/attack_result/rasp_rule_sample.rb +52 -0
- data/lib/contrast/agent/reporting/attack_result/response_type.rb +29 -0
- data/lib/contrast/agent/reporting/attack_result/user_input.rb +87 -0
- data/lib/contrast/agent/reporting/masker/masker.rb +243 -0
- data/lib/contrast/agent/reporting/masker/masker_utils.rb +62 -0
- data/lib/contrast/agent/reporting/report.rb +2 -0
- data/lib/contrast/agent/reporting/reporter.rb +29 -22
- data/lib/contrast/agent/reporting/reporter_heartbeat.rb +49 -0
- data/lib/contrast/agent/reporting/reporting_events/agent_startup.rb +34 -0
- data/lib/contrast/agent/reporting/reporting_events/application_activity.rb +51 -0
- data/lib/contrast/agent/reporting/reporting_events/application_defend_activity.rb +96 -0
- data/lib/contrast/agent/reporting/reporting_events/application_defend_attack_activity.rb +70 -0
- data/lib/contrast/agent/reporting/reporting_events/application_defend_attack_sample.rb +182 -0
- data/lib/contrast/agent/reporting/reporting_events/application_defend_attack_sample_activity.rb +56 -0
- data/lib/contrast/agent/reporting/reporting_events/application_defend_attack_sample_stack.rb +22 -0
- data/lib/contrast/agent/reporting/reporting_events/application_defend_attacker_activity.rb +70 -0
- data/lib/contrast/agent/reporting/reporting_events/application_inventory.rb +13 -5
- data/lib/contrast/agent/reporting/reporting_events/application_inventory_activity.rb +60 -0
- data/lib/contrast/agent/reporting/reporting_events/application_reporting_event.rb +27 -0
- data/lib/contrast/agent/reporting/reporting_events/application_startup.rb +44 -0
- data/lib/contrast/agent/reporting/reporting_events/application_startup_instrumentation.rb +27 -0
- data/lib/contrast/agent/reporting/reporting_events/application_update.rb +7 -12
- data/lib/contrast/agent/reporting/reporting_events/discovered_route.rb +1 -1
- data/lib/contrast/agent/reporting/reporting_events/finding.rb +10 -4
- data/lib/contrast/agent/reporting/reporting_events/finding_event.rb +2 -4
- data/lib/contrast/agent/reporting/reporting_events/finding_event_object.rb +3 -3
- data/lib/contrast/agent/reporting/reporting_events/library_usage_observation.rb +5 -5
- data/lib/contrast/agent/reporting/reporting_events/observed_library_usage.rb +6 -2
- data/lib/contrast/agent/reporting/reporting_events/observed_route.rb +16 -12
- data/lib/contrast/agent/reporting/reporting_events/poll.rb +6 -2
- data/lib/contrast/agent/reporting/reporting_events/preflight.rb +10 -8
- data/lib/contrast/agent/reporting/reporting_events/preflight_message.rb +8 -11
- data/lib/contrast/agent/reporting/reporting_events/reporting_event.rb +2 -1
- data/lib/contrast/agent/reporting/reporting_events/route_coverage.rb +8 -6
- data/lib/contrast/agent/reporting/reporting_events/server_activity.rb +12 -20
- data/lib/contrast/agent/reporting/reporting_events/server_reporting_event.rb +27 -0
- data/lib/contrast/agent/reporting/reporting_utilities/audit.rb +17 -27
- data/lib/contrast/agent/reporting/reporting_utilities/build_preflight.rb +38 -0
- data/lib/contrast/agent/reporting/reporting_utilities/dtm_message.rb +8 -0
- data/lib/contrast/agent/reporting/reporting_utilities/endpoints.rb +6 -0
- data/lib/contrast/agent/reporting/reporting_utilities/headers.rb +1 -2
- data/lib/contrast/agent/reporting/reporting_utilities/reporter_client.rb +29 -13
- data/lib/contrast/agent/reporting/reporting_utilities/reporter_client_utils.rb +64 -76
- data/lib/contrast/agent/reporting/reporting_utilities/reporting_storage.rb +1 -1
- data/lib/contrast/agent/reporting/reporting_utilities/response.rb +17 -7
- data/lib/contrast/agent/reporting/reporting_utilities/response_extractor.rb +100 -0
- data/lib/contrast/agent/reporting/reporting_utilities/response_handler.rb +75 -13
- data/lib/contrast/agent/reporting/reporting_utilities/response_handler_mode.rb +63 -0
- data/lib/contrast/agent/reporting/reporting_utilities/response_handler_utils.rb +163 -122
- data/lib/contrast/agent/reporting/settings/application_settings.rb +10 -1
- data/lib/contrast/agent/reporting/settings/assess.rb +5 -5
- data/lib/contrast/agent/reporting/settings/assess_server_feature.rb +7 -35
- data/lib/contrast/agent/reporting/settings/exclusions.rb +3 -3
- data/lib/contrast/agent/reporting/settings/protect.rb +21 -6
- data/lib/contrast/agent/reporting/settings/protect_server_feature.rb +6 -6
- data/lib/contrast/agent/reporting/settings/reaction.rb +3 -3
- data/lib/contrast/agent/reporting/settings/sampling.rb +36 -0
- data/lib/contrast/agent/reporting/settings/sensitive_data_masking.rb +110 -0
- data/lib/contrast/agent/reporting/settings/sensitive_data_masking_rule.rb +58 -0
- data/lib/contrast/agent/reporting/settings/server_features.rb +2 -2
- data/lib/contrast/agent/request.rb +5 -5
- data/lib/contrast/agent/request_context.rb +25 -21
- data/lib/contrast/agent/request_context_extend.rb +12 -25
- data/lib/contrast/agent/request_handler.rb +7 -3
- data/lib/contrast/agent/response.rb +2 -0
- data/lib/contrast/agent/rule_set.rb +2 -2
- data/lib/contrast/agent/scope.rb +1 -1
- data/lib/contrast/agent/service_heartbeat.rb +6 -48
- data/lib/contrast/agent/static_analysis.rb +1 -1
- data/lib/contrast/agent/telemetry/base.rb +155 -0
- data/lib/contrast/agent/telemetry/events/event.rb +35 -0
- data/lib/contrast/agent/telemetry/events/exceptions/obfuscate.rb +119 -0
- data/lib/contrast/agent/telemetry/events/exceptions/telemetry_exception_base.rb +59 -0
- data/lib/contrast/agent/telemetry/events/exceptions/telemetry_exception_event.rb +44 -0
- data/lib/contrast/agent/telemetry/events/exceptions/telemetry_exception_message.rb +115 -0
- data/lib/contrast/agent/telemetry/events/exceptions/telemetry_exception_message_exception.rb +83 -0
- data/lib/contrast/agent/telemetry/events/exceptions/telemetry_exception_stack_frame.rb +64 -0
- data/lib/contrast/agent/telemetry/events/exceptions/telemetry_exceptions.rb +20 -0
- data/lib/contrast/agent/telemetry/events/exceptions/telemetry_exceptions_report.rb +30 -0
- data/lib/contrast/agent/telemetry/events/metric_event.rb +28 -0
- data/lib/contrast/agent/telemetry/events/startup_metrics_event.rb +123 -0
- data/lib/contrast/agent/thread_watcher.rb +52 -68
- data/lib/contrast/agent/version.rb +1 -1
- data/lib/contrast/agent/worker_thread.rb +8 -0
- data/lib/contrast/agent.rb +4 -3
- data/lib/contrast/api/communication/messaging_queue.rb +29 -12
- data/lib/contrast/api/communication/response_processor.rb +7 -10
- data/lib/contrast/api/communication/service_lifecycle.rb +1 -1
- data/lib/contrast/api/communication/socket.rb +1 -1
- data/lib/contrast/api/communication/socket_client.rb +1 -1
- data/lib/contrast/api/communication/speedracer.rb +3 -3
- data/lib/contrast/api/decorators/activity.rb +33 -0
- data/lib/contrast/api/decorators/address.rb +1 -1
- data/lib/contrast/api/decorators/agent_startup.rb +10 -9
- data/lib/contrast/api/decorators/application_settings.rb +1 -1
- data/lib/contrast/api/decorators/application_startup.rb +4 -4
- data/lib/contrast/api/decorators/http_request.rb +1 -1
- data/lib/contrast/api/decorators/response_type.rb +17 -0
- data/lib/contrast/api/decorators.rb +1 -0
- data/lib/contrast/components/agent.rb +1 -1
- data/lib/contrast/components/app_context.rb +0 -4
- data/lib/contrast/components/assess.rb +14 -0
- data/lib/contrast/components/base.rb +1 -1
- data/lib/contrast/components/config.rb +19 -28
- data/lib/contrast/components/contrast_service.rb +13 -1
- data/lib/contrast/components/protect.rb +2 -2
- data/lib/contrast/components/sampling.rb +8 -12
- data/lib/contrast/components/settings.rb +151 -19
- data/lib/contrast/config/agent_configuration.rb +34 -41
- data/lib/contrast/config/api_configuration.rb +16 -75
- data/lib/contrast/config/api_proxy_configuration.rb +9 -48
- data/lib/contrast/config/application_configuration.rb +24 -95
- data/lib/contrast/config/assess_configuration.rb +21 -76
- data/lib/contrast/config/assess_rules_configuration.rb +13 -38
- data/lib/contrast/config/base_configuration.rb +11 -76
- data/lib/contrast/config/certification_configuration.rb +15 -68
- data/lib/contrast/config/exception_configuration.rb +15 -59
- data/lib/contrast/config/heap_dump_configuration.rb +19 -73
- data/lib/contrast/config/inventory_configuration.rb +11 -55
- data/lib/contrast/config/logger_configuration.rb +8 -41
- data/lib/contrast/config/protect_configuration.rb +23 -10
- data/lib/contrast/config/protect_rule_configuration.rb +23 -37
- data/lib/contrast/config/protect_rules_configuration.rb +39 -43
- data/lib/contrast/config/request_audit_configuration.rb +16 -55
- data/lib/contrast/config/root_configuration.rb +71 -14
- data/lib/contrast/config/ruby_configuration.rb +14 -47
- data/lib/contrast/config/sampling_configuration.rb +12 -65
- data/lib/contrast/config/server_configuration.rb +13 -45
- data/lib/contrast/config/service_configuration.rb +18 -54
- data/lib/contrast/configuration.rb +25 -17
- data/lib/contrast/extension/assess/array.rb +1 -1
- data/lib/contrast/extension/assess/erb.rb +1 -1
- data/lib/contrast/extension/assess/marshal.rb +1 -1
- data/lib/contrast/extension/assess/string.rb +20 -1
- data/lib/contrast/extension/extension.rb +2 -2
- data/lib/contrast/extension/module.rb +0 -1
- data/lib/contrast/framework/base_support.rb +8 -8
- data/lib/contrast/framework/grape/support.rb +3 -3
- data/lib/contrast/framework/manager.rb +7 -7
- data/lib/contrast/framework/manager_extend.rb +1 -1
- data/lib/contrast/framework/rack/patch/session_cookie.rb +1 -1
- data/lib/contrast/framework/rails/patch/action_controller_live_buffer.rb +14 -3
- data/lib/contrast/framework/rails/patch/assess_configuration.rb +3 -3
- data/lib/contrast/framework/rails/patch/rails_application_configuration.rb +1 -1
- data/lib/contrast/framework/rails/patch/support.rb +14 -46
- data/lib/contrast/framework/rails/support.rb +2 -2
- data/lib/contrast/framework/sinatra/support.rb +1 -1
- data/lib/contrast/logger/aliased_logging.rb +94 -0
- data/lib/contrast/logger/application.rb +1 -5
- data/lib/contrast/logger/cef_log.rb +15 -15
- data/lib/contrast/logger/format.rb +1 -1
- data/lib/contrast/logger/log.rb +8 -8
- data/lib/contrast/tasks/config.rb +100 -4
- data/lib/contrast/tasks/service.rb +2 -2
- data/lib/contrast/utils/assess/object_store.rb +36 -0
- data/lib/contrast/utils/assess/propagation_method_utils.rb +6 -0
- data/lib/contrast/utils/assess/tracking_util.rb +4 -4
- data/lib/contrast/utils/class_util.rb +9 -22
- data/lib/contrast/utils/findings.rb +3 -3
- data/lib/contrast/utils/hash_digest.rb +6 -7
- data/lib/contrast/utils/head_dump_utils_extend.rb +1 -1
- data/lib/contrast/utils/input_classification.rb +73 -0
- data/lib/contrast/utils/invalid_configuration_util.rb +2 -2
- data/lib/contrast/utils/log_utils.rb +7 -5
- data/lib/contrast/utils/lru_cache.rb +1 -1
- data/lib/contrast/utils/metrics_hash.rb +1 -1
- data/lib/contrast/utils/middleware_utils.rb +15 -14
- data/lib/contrast/utils/net_http_base.rb +5 -5
- data/lib/contrast/utils/object_share.rb +2 -1
- data/lib/contrast/utils/os.rb +1 -6
- data/lib/contrast/utils/patching/policy/patch_utils.rb +6 -7
- data/lib/contrast/utils/request_utils.rb +2 -2
- data/lib/contrast/utils/response_utils.rb +18 -33
- data/lib/contrast/utils/sha256_builder.rb +4 -4
- data/lib/contrast/utils/stack_trace_utils.rb +31 -13
- data/lib/contrast/utils/telemetry.rb +22 -7
- data/lib/contrast/utils/telemetry_client.rb +28 -16
- data/lib/contrast/utils/telemetry_hash.rb +41 -0
- data/lib/contrast/utils/telemetry_identifier.rb +18 -3
- data/lib/contrast/utils/timer.rb +1 -1
- data/lib/contrast.rb +9 -0
- data/resources/assess/policy.json +99 -1
- data/resources/deadzone/policy.json +0 -86
- data/ruby-agent.gemspec +10 -9
- data/service_executables/VERSION +1 -1
- data/service_executables/linux/contrast-service +0 -0
- data/service_executables/mac/contrast-service +0 -0
- metadata +99 -29
- data/lib/contrast/agent/metric_telemetry_event.rb +0 -26
- data/lib/contrast/agent/startup_metrics_telemetry_event.rb +0 -121
- data/lib/contrast/agent/telemetry.rb +0 -137
- data/lib/contrast/agent/telemetry_event.rb +0 -33
- data/lib/contrast/utils/exclude_key.rb +0 -20
@@ -35,25 +35,29 @@ VALUE contrast_patch_call_original(const VALUE *args) {
|
|
35
35
|
method = args[3];
|
36
36
|
method_id = SYM2ID(method);
|
37
37
|
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
38
|
+
/* It looks like we can find the last Ruby block given so long as we don't
|
39
|
+
* change Ruby method scope (always call this function from C, not Ruby),
|
40
|
+
* which is the point of this C call.
|
41
|
+
*/
|
42
|
+
/* Ruby >= 2.7 */
|
43
|
+
#ifdef RB_PASS_CALLED_KEYWORDS
|
44
|
+
if (rb_block_given_p()) {
|
45
|
+
return rb_funcall_with_block_kw(object, method_id, argc, params,
|
46
|
+
rb_block_proc(),
|
47
|
+
RB_PASS_CALLED_KEYWORDS);
|
48
|
+
} else {
|
49
|
+
return rb_funcallv_kw(object, method_id, argc, params,
|
50
|
+
RB_PASS_CALLED_KEYWORDS);
|
51
|
+
}
|
52
|
+
/* Ruby < 2.7 */
|
53
|
+
#else
|
54
|
+
if (rb_block_given_p()) {
|
55
|
+
return rb_funcall_with_block(object, method_id, argc, params,
|
56
|
+
rb_block_proc());
|
57
|
+
} else {
|
58
|
+
return rb_funcall2(object, method_id, argc, params);
|
59
|
+
}
|
60
|
+
#endif
|
57
61
|
}
|
58
62
|
|
59
63
|
VALUE contrast_call_pre_patch(const VALUE method_policy, const VALUE method,
|
@@ -94,7 +98,7 @@ VALUE rescue_func(VALUE arg1) {
|
|
94
98
|
exception = rb_errinfo();
|
95
99
|
rb_exc_raise(exception);
|
96
100
|
|
97
|
-
|
101
|
+
return Qnil;
|
98
102
|
}
|
99
103
|
|
100
104
|
VALUE contrast_patch_call_ensure(const VALUE *args) {
|
@@ -121,7 +125,8 @@ VALUE ensure_wrapper(const VALUE *args) {
|
|
121
125
|
original_args = (VALUE)args[1];
|
122
126
|
ensure_args = (VALUE)args[2];
|
123
127
|
|
124
|
-
|
128
|
+
return rb_ensure(original_method, original_args, contrast_patch_call_ensure,
|
129
|
+
(VALUE)ensure_args);
|
125
130
|
}
|
126
131
|
|
127
132
|
VALUE contrast_call_super(const VALUE *args) {
|
@@ -134,7 +139,8 @@ VALUE contrast_call_super(const VALUE *args) {
|
|
134
139
|
}
|
135
140
|
|
136
141
|
VALUE contrast_run_patches(const VALUE *wrapped_args) {
|
137
|
-
VALUE impl, method, method_policy, object, original_args, original_ret,
|
142
|
+
VALUE impl, method, method_policy, object, original_args, original_ret,
|
143
|
+
preshift, transformed_ret;
|
138
144
|
int argc;
|
139
145
|
VALUE *argv;
|
140
146
|
VALUE ensure_args[6];
|
@@ -198,12 +204,14 @@ VALUE contrast_run_patches(const VALUE *wrapped_args) {
|
|
198
204
|
switch (impl) {
|
199
205
|
case IMPL_ALIAS_INSTANCE:
|
200
206
|
case IMPL_ALIAS_SINGLETON:
|
201
|
-
original_ret =
|
207
|
+
original_ret =
|
208
|
+
rb_rescue(ensure_wrapper, rescue_wrapper_args, rescue_func, Qnil);
|
202
209
|
break;
|
203
210
|
case IMPL_PREPEND_INSTANCE:
|
204
211
|
case IMPL_PREPEND_SINGLETON:
|
205
212
|
rescue_wrapper_args[0] = contrast_call_super;
|
206
|
-
original_ret =
|
213
|
+
original_ret =
|
214
|
+
rb_rescue(ensure_wrapper, rescue_wrapper_args, rescue_func, Qnil);
|
207
215
|
break;
|
208
216
|
};
|
209
217
|
|
@@ -272,9 +280,9 @@ VALUE contrast_patch_dispatch(const int argc, const VALUE *argv,
|
|
272
280
|
rb_funcall(patch_status, rb_sym_info_for, 3, object, method, Qtrue);
|
273
281
|
break;
|
274
282
|
case IMPL_PREPEND_SINGLETON:
|
275
|
-
|
276
|
-
|
277
|
-
|
283
|
+
known = rb_funcall(patch_status, rb_sym_info_for, 3, object, method,
|
284
|
+
Qfalse);
|
285
|
+
break;
|
278
286
|
case IMPL_ALIAS_SINGLETON:
|
279
287
|
known = rb_funcall(patch_status, rb_sym_info_for, 3, object, method,
|
280
288
|
Qfalse);
|
@@ -337,14 +345,14 @@ VALUE contrast_patch_dispatch(const int argc, const VALUE *argv,
|
|
337
345
|
wrapped_args[5] = INT2NUM(argc);
|
338
346
|
wrapped_args[6] = (VALUE)argv;
|
339
347
|
|
340
|
-
return rb_ensure(contrast_run_patches, (VALUE)wrapped_args,
|
348
|
+
return rb_ensure(contrast_run_patches, (VALUE)wrapped_args,
|
349
|
+
contrast_ensure_function, method_policy);
|
341
350
|
|
342
351
|
call_original:
|
343
352
|
|
344
353
|
/* exit scope */
|
345
354
|
contrast_ensure_function(method_policy);
|
346
355
|
|
347
|
-
|
348
356
|
switch (impl) {
|
349
357
|
case IMPL_ALIAS_INSTANCE:
|
350
358
|
case IMPL_ALIAS_SINGLETON:
|
@@ -366,19 +374,22 @@ VALUE contrast_alias_singleton_patch(const int argc, const VALUE *argv,
|
|
366
374
|
}
|
367
375
|
|
368
376
|
VALUE contrast_prepend_instance_patch(const int argc, const VALUE *argv,
|
369
|
-
|
377
|
+
const VALUE object) {
|
370
378
|
return contrast_patch_dispatch(argc, argv, IMPL_PREPEND_INSTANCE, object);
|
371
379
|
}
|
372
380
|
|
373
381
|
VALUE contrast_prepend_singleton_patch(const int argc, const VALUE *argv,
|
374
|
-
|
382
|
+
const VALUE object) {
|
375
383
|
return contrast_patch_dispatch(argc, argv, IMPL_PREPEND_SINGLETON, object);
|
376
384
|
}
|
377
385
|
|
378
|
-
VALUE contrast_patch_define_method(const VALUE self, const VALUE clazz,
|
386
|
+
VALUE contrast_patch_define_method(const VALUE self, const VALUE clazz,
|
387
|
+
const VALUE method_policy,
|
379
388
|
const VALUE cs_method) {
|
380
|
-
const VALUE original_method_name =
|
381
|
-
|
389
|
+
const VALUE original_method_name =
|
390
|
+
rb_funcall(method_policy, rb_sym_method_name, 0);
|
391
|
+
const VALUE is_instance_method =
|
392
|
+
rb_funcall(method_policy, rb_sym_instance_method, 0);
|
382
393
|
char *cStr;
|
383
394
|
VALUE str;
|
384
395
|
rb_funcall(patch_status, rb_sym_set_info_for, 5, clazz,
|
@@ -444,8 +455,8 @@ VALUE contrast_patch_prepend(const VALUE self, const VALUE originalModule,
|
|
444
455
|
const VALUE is_instance_method =
|
445
456
|
rb_funcall(method_policy, rb_sym_instance_method, 0);
|
446
457
|
|
447
|
-
// Set the value for instance or singleton method
|
448
|
-
if (RTEST(is_instance_method)){
|
458
|
+
// Set the value for instance or singleton method
|
459
|
+
if (RTEST(is_instance_method)) {
|
449
460
|
rb_funcall(patch_status, rb_sym_set_info_for, 5, originalModule,
|
450
461
|
original_method_name, method_policy, instance, Qnil);
|
451
462
|
|
@@ -462,20 +473,22 @@ VALUE contrast_patch_prepend(const VALUE self, const VALUE originalModule,
|
|
462
473
|
rb_define_private_method(module, cMethodName,
|
463
474
|
contrast_prepend_instance_patch, -1);
|
464
475
|
} else {
|
465
|
-
rb_define_method(module, cMethodName,
|
476
|
+
rb_define_method(module, cMethodName,
|
477
|
+
contrast_prepend_instance_patch, -1);
|
466
478
|
}
|
467
479
|
} else {
|
468
|
-
rb_define_singleton_method(module, cMethodName,
|
469
|
-
-1);
|
480
|
+
rb_define_singleton_method(module, cMethodName,
|
481
|
+
contrast_prepend_singleton_patch, -1);
|
470
482
|
}
|
471
483
|
rb_prepend_module(originalModule, module);
|
472
484
|
|
473
485
|
if (rb_ver_below_three()) {
|
474
486
|
VALUE module_at;
|
475
|
-
VALUE rb_incl_in_mod_ary =
|
487
|
+
VALUE rb_incl_in_mod_ary =
|
488
|
+
rb_funcall(originalModule, rb_intern("included_in"), 0);
|
476
489
|
if (RB_TYPE_P(rb_incl_in_mod_ary, T_ARRAY)) {
|
477
490
|
int i = 0;
|
478
|
-
int size =
|
491
|
+
int size = RARRAY_LEN(rb_incl_in_mod_ary);
|
479
492
|
for (i = 0; i < size; ++i) {
|
480
493
|
module_at = rb_ary_entry(rb_incl_in_mod_ary, i);
|
481
494
|
if (RB_TYPE_P(module_at, T_MODULE)) {
|
@@ -483,7 +496,7 @@ VALUE contrast_patch_prepend(const VALUE self, const VALUE originalModule,
|
|
483
496
|
}
|
484
497
|
}
|
485
498
|
}
|
486
|
-
|
499
|
+
}
|
487
500
|
return Qtrue;
|
488
501
|
}
|
489
502
|
|
@@ -512,7 +525,6 @@ void Init_cs__contrast_patch(void) {
|
|
512
525
|
rb_sym_scopes_to_enter = rb_intern("scopes_to_enter");
|
513
526
|
rb_sym_scopes_to_exit = rb_intern("scopes_to_exit");
|
514
527
|
|
515
|
-
|
516
528
|
rb_define_module_function(contrast_patcher(), "contrast_define_method",
|
517
529
|
contrast_patch_define_method, 3);
|
518
530
|
|
@@ -524,5 +536,4 @@ void Init_cs__contrast_patch(void) {
|
|
524
536
|
|
525
537
|
/* preshift_class = Contrast::Agent::Assess::PreShift */
|
526
538
|
preshift_class = rb_define_class_under(assess, "PreShift", rb_cObject);
|
527
|
-
|
528
539
|
}
|
@@ -8,24 +8,27 @@
|
|
8
8
|
|
9
9
|
VALUE contrast, utils, os;
|
10
10
|
|
11
|
-
VALUE contrast_get_system_information()
|
12
|
-
{
|
11
|
+
VALUE contrast_get_system_information() {
|
13
12
|
struct utsname uname_pointer;
|
14
13
|
|
15
|
-
uname
|
14
|
+
uname(&uname_pointer);
|
16
15
|
|
17
16
|
VALUE rb_data_hash = rb_hash_new();
|
18
|
-
rb_hash_aset(rb_data_hash, rb_str_new2("os_type"),
|
19
|
-
|
20
|
-
rb_hash_aset(rb_data_hash, rb_str_new2("
|
21
|
-
|
17
|
+
rb_hash_aset(rb_data_hash, rb_str_new2("os_type"),
|
18
|
+
rb_str_new2(uname_pointer.sysname));
|
19
|
+
rb_hash_aset(rb_data_hash, rb_str_new2("os_version"),
|
20
|
+
rb_str_new2(uname_pointer.release));
|
21
|
+
rb_hash_aset(rb_data_hash, rb_str_new2("os_complete_version"),
|
22
|
+
rb_str_new2(uname_pointer.version));
|
23
|
+
rb_hash_aset(rb_data_hash, rb_str_new2("os_arch"),
|
24
|
+
rb_str_new2(uname_pointer.machine));
|
22
25
|
return rb_data_hash;
|
23
26
|
}
|
24
27
|
|
25
|
-
void Init_cs__os_information(void)
|
26
|
-
{
|
28
|
+
void Init_cs__os_information(void) {
|
27
29
|
contrast = rb_define_module("Contrast");
|
28
30
|
utils = rb_define_module_under(contrast, "Utils");
|
29
31
|
os = rb_define_module_under(utils, "OS");
|
30
|
-
rb_define_module_function(os, "get_system_information",
|
32
|
+
rb_define_module_function(os, "get_system_information",
|
33
|
+
contrast_get_system_information, 0);
|
31
34
|
}
|