contrast-agent 5.1.0 → 6.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/ext/cs__assess_array/cs__assess_array.c +7 -0
- data/ext/cs__assess_basic_object/cs__assess_basic_object.c +19 -5
- 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 +7 -5
- data/ext/cs__assess_marshal_module/cs__assess_marshal_module.c +26 -12
- data/ext/cs__assess_module/cs__assess_module.c +7 -7
- data/ext/cs__assess_string/cs__assess_string.c +13 -1
- data/ext/cs__common/cs__common.c +16 -11
- data/ext/cs__common/cs__common.h +1 -0
- data/ext/cs__contrast_patch/cs__contrast_patch.c +100 -64
- data/ext/cs__contrast_patch/cs__contrast_patch.h +2 -0
- data/ext/cs__os_information/cs__os_information.c +13 -10
- data/ext/cs__scope/cs__scope.c +796 -0
- data/ext/cs__scope/cs__scope.h +88 -0
- data/ext/cs__scope/extconf.rb +5 -0
- data/lib/contrast/agent/assess/contrast_event.rb +20 -13
- data/lib/contrast/agent/assess/contrast_object.rb +4 -1
- data/lib/contrast/agent/assess/finalizers/hash.rb +2 -0
- data/lib/contrast/agent/assess/policy/policy_node.rb +50 -27
- data/lib/contrast/agent/assess/policy/policy_node_utils.rb +51 -0
- data/lib/contrast/agent/assess/policy/preshift.rb +8 -2
- data/lib/contrast/agent/assess/policy/propagation_method.rb +47 -13
- data/lib/contrast/agent/assess/policy/propagation_node.rb +2 -5
- data/lib/contrast/agent/assess/policy/propagator/buffer.rb +118 -0
- data/lib/contrast/agent/assess/policy/propagator/keep.rb +19 -4
- data/lib/contrast/agent/assess/policy/propagator/match_data.rb +2 -0
- 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/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 +1 -1
- 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/trigger_method.rb +6 -1
- data/lib/contrast/agent/assess/property/tagged.rb +1 -1
- data/lib/contrast/agent/assess/rule/response/{autocomplete_rule.rb → auto_complete_rule.rb} +4 -3
- data/lib/contrast/agent/assess/rule/response/base_rule.rb +12 -79
- data/lib/contrast/agent/assess/rule/response/body_rule.rb +109 -0
- data/lib/contrast/agent/assess/rule/response/cache_control_header_rule.rb +157 -0
- data/lib/contrast/agent/assess/rule/response/click_jacking_header_rule.rb +26 -0
- data/lib/contrast/agent/assess/rule/response/csp_header_insecure_rule.rb +14 -15
- data/lib/contrast/agent/assess/rule/response/csp_header_missing_rule.rb +5 -25
- data/lib/contrast/agent/assess/rule/response/framework/rails_support.rb +29 -0
- data/lib/contrast/agent/assess/rule/response/header_rule.rb +70 -0
- data/lib/contrast/agent/assess/rule/response/hsts_header_rule.rb +12 -36
- data/lib/contrast/agent/assess/rule/response/parameters_pollution_rule.rb +2 -1
- data/lib/contrast/agent/assess/rule/response/x_content_type_header_rule.rb +26 -0
- data/lib/contrast/agent/assess/rule/response/x_xss_protection_header_rule.rb +35 -0
- 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/middleware.rb +4 -1
- data/lib/contrast/agent/patching/policy/after_load_patcher.rb +1 -3
- data/lib/contrast/agent/patching/policy/patch.rb +2 -6
- data/lib/contrast/agent/patching/policy/patcher.rb +4 -4
- data/lib/contrast/agent/patching/policy/policy_node.rb +15 -2
- data/lib/contrast/agent/protect/exploitable_collection.rb +38 -0
- data/lib/contrast/agent/protect/input_analyzer/input_analyzer.rb +147 -0
- data/lib/contrast/agent/protect/policy/applies_no_sqli_rule.rb +2 -1
- data/lib/contrast/agent/protect/policy/applies_path_traversal_rule.rb +2 -2
- data/lib/contrast/agent/protect/rule/base.rb +61 -2
- data/lib/contrast/agent/protect/rule/base_service.rb +12 -1
- data/lib/contrast/agent/protect/rule/cmd_injection.rb +15 -0
- 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/deserialization.rb +6 -0
- 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 +13 -1
- 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 -0
- data/lib/contrast/agent/protect/rule/path_traversal.rb +1 -0
- data/lib/contrast/agent/protect/rule/sqli/sqli_input_classification.rb +88 -0
- data/lib/contrast/agent/protect/rule/sqli/sqli_worth_watching.rb +118 -0
- data/lib/contrast/agent/protect/rule/sqli.rb +33 -0
- 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/xxe.rb +4 -0
- 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/input_analysis/input_analysis.rb +44 -0
- data/lib/contrast/agent/reporting/input_analysis/input_analysis_result.rb +115 -0
- data/lib/contrast/agent/reporting/input_analysis/input_type.rb +44 -0
- data/lib/contrast/agent/reporting/input_analysis/score_level.rb +21 -0
- data/lib/contrast/agent/reporting/masker/masker.rb +246 -0
- data/lib/contrast/agent/reporting/masker/masker_utils.rb +58 -0
- data/lib/contrast/agent/reporting/report.rb +3 -0
- data/lib/contrast/agent/reporting/reporter.rb +31 -12
- data/lib/contrast/agent/reporting/reporting_events/agent_startup.rb +30 -0
- data/lib/contrast/agent/reporting/reporting_events/application_inventory.rb +7 -3
- data/lib/contrast/agent/reporting/reporting_events/application_startup.rb +40 -0
- data/lib/contrast/agent/reporting/reporting_events/application_startup_instrumentation.rb +27 -0
- data/lib/contrast/agent/reporting/reporting_events/finding.rb +69 -36
- data/lib/contrast/agent/reporting/reporting_events/finding_event.rb +88 -59
- data/lib/contrast/agent/reporting/reporting_events/{finding_object.rb → finding_event_object.rb} +24 -20
- data/lib/contrast/agent/reporting/reporting_events/finding_event_parent_object.rb +39 -0
- data/lib/contrast/agent/reporting/reporting_events/finding_event_property.rb +40 -0
- data/lib/contrast/agent/reporting/reporting_events/{finding_signature.rb → finding_event_signature.rb} +29 -24
- data/lib/contrast/agent/reporting/reporting_events/finding_event_source.rb +12 -8
- data/lib/contrast/agent/reporting/reporting_events/{finding_stack.rb → finding_event_stack.rb} +23 -19
- data/lib/contrast/agent/reporting/reporting_events/{finding_taint_range.rb → finding_event_taint_range.rb} +17 -15
- data/lib/contrast/agent/reporting/reporting_events/finding_request.rb +26 -53
- data/lib/contrast/agent/reporting/reporting_events/library_usage_observation.rb +5 -5
- data/lib/contrast/agent/reporting/reporting_events/observed_route.rb +9 -9
- data/lib/contrast/agent/reporting/reporting_events/poll.rb +29 -0
- data/lib/contrast/agent/reporting/reporting_events/preflight_message.rb +2 -1
- data/lib/contrast/agent/reporting/reporting_events/reporting_event.rb +6 -4
- data/lib/contrast/agent/reporting/reporting_events/route_coverage.rb +8 -6
- data/lib/contrast/agent/reporting/reporting_events/route_discovery.rb +1 -0
- data/lib/contrast/agent/reporting/reporting_events/server_activity.rb +1 -1
- data/lib/contrast/agent/reporting/reporting_utilities/audit.rb +10 -3
- data/lib/contrast/agent/reporting/reporting_utilities/endpoints.rb +0 -1
- data/lib/contrast/agent/reporting/reporting_utilities/reporter_client.rb +17 -5
- data/lib/contrast/agent/reporting/reporting_utilities/reporter_client_utils.rb +54 -45
- data/lib/contrast/agent/reporting/reporting_utilities/reporting_storage.rb +1 -1
- data/lib/contrast/agent/reporting/reporting_utilities/response_extractor.rb +97 -0
- data/lib/contrast/agent/reporting/reporting_utilities/response_handler.rb +69 -7
- data/lib/contrast/agent/reporting/reporting_utilities/response_handler_mode.rb +63 -0
- data/lib/contrast/agent/reporting/reporting_utilities/response_handler_utils.rb +123 -85
- data/lib/contrast/agent/reporting/settings/application_settings.rb +9 -0
- data/lib/contrast/agent/reporting/settings/assess_server_feature.rb +5 -33
- data/lib/contrast/agent/reporting/settings/protect_server_feature.rb +1 -1
- 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/request_context.rb +7 -2
- data/lib/contrast/agent/request_context_extend.rb +85 -21
- data/lib/contrast/agent/request_handler.rb +4 -0
- data/lib/contrast/agent/scope.rb +102 -107
- data/lib/contrast/agent/service_heartbeat.rb +45 -2
- data/lib/contrast/agent/telemetry/events/exceptions/telemetry_exception_base.rb +51 -0
- data/lib/contrast/agent/telemetry/events/exceptions/telemetry_exception_event.rb +36 -0
- data/lib/contrast/agent/telemetry/events/exceptions/telemetry_exception_message.rb +97 -0
- data/lib/contrast/agent/telemetry/events/exceptions/telemetry_exception_message_exception.rb +65 -0
- data/lib/contrast/agent/telemetry/events/exceptions/telemetry_exception_stack_frame.rb +47 -0
- data/lib/contrast/agent/{metric_telemetry_event.rb → telemetry/events/metric_telemetry_event.rb} +1 -1
- data/lib/contrast/agent/{startup_metrics_telemetry_event.rb → telemetry/events/startup_metrics_telemetry_event.rb} +3 -3
- data/lib/contrast/agent/{telemetry_event.rb → telemetry/events/telemetry_event.rb} +1 -1
- data/lib/contrast/agent/{telemetry.rb → telemetry/telemetry.rb} +32 -19
- data/lib/contrast/agent/thread_watcher.rb +1 -1
- data/lib/contrast/agent/version.rb +1 -1
- data/lib/contrast/agent.rb +3 -0
- data/lib/contrast/api/communication/speedracer.rb +1 -1
- data/lib/contrast/api/decorators/address.rb +1 -1
- data/lib/contrast/api/decorators/bot_blocker.rb +37 -0
- data/lib/contrast/api/decorators/ip_denylist.rb +37 -0
- data/lib/contrast/api/decorators/rasp_rule_sample.rb +29 -0
- data/lib/contrast/api/decorators/response_type.rb +30 -0
- data/lib/contrast/api/decorators/user_input.rb +11 -1
- data/lib/contrast/api/decorators/virtual_patch.rb +34 -0
- data/lib/contrast/api/decorators.rb +1 -0
- data/lib/contrast/components/app_context.rb +0 -4
- data/lib/contrast/components/assess.rb +14 -0
- data/lib/contrast/components/logger.rb +5 -0
- data/lib/contrast/components/protect.rb +6 -4
- data/lib/contrast/components/sampling.rb +7 -11
- data/lib/contrast/components/scope.rb +98 -91
- data/lib/contrast/components/settings.rb +106 -8
- data/lib/contrast/config/agent_configuration.rb +41 -12
- data/lib/contrast/config/api_configuration.rb +37 -12
- data/lib/contrast/config/api_proxy_configuration.rb +12 -3
- data/lib/contrast/config/application_configuration.rb +38 -14
- data/lib/contrast/config/assess_configuration.rb +47 -12
- data/lib/contrast/config/assess_rules_configuration.rb +15 -3
- data/lib/contrast/config/base_configuration.rb +18 -50
- data/lib/contrast/config/certification_configuration.rb +17 -3
- data/lib/contrast/config/exception_configuration.rb +14 -3
- data/lib/contrast/config/heap_dump_configuration.rb +43 -17
- data/lib/contrast/config/inventory_configuration.rb +17 -3
- data/lib/contrast/config/logger_configuration.rb +10 -3
- data/lib/contrast/config/protect_configuration.rb +17 -7
- data/lib/contrast/config/protect_rule_configuration.rb +17 -8
- data/lib/contrast/config/protect_rules_configuration.rb +115 -17
- data/lib/contrast/config/request_audit_configuration.rb +26 -3
- data/lib/contrast/config/root_configuration.rb +52 -12
- data/lib/contrast/config/ruby_configuration.rb +60 -22
- data/lib/contrast/config/sampling_configuration.rb +19 -9
- data/lib/contrast/config/server_configuration.rb +19 -10
- data/lib/contrast/config/service_configuration.rb +27 -11
- data/lib/contrast/configuration.rb +5 -3
- data/lib/contrast/extension/assess/string.rb +20 -1
- data/lib/contrast/extension/module.rb +0 -1
- data/lib/contrast/framework/manager.rb +2 -2
- data/lib/contrast/logger/application.rb +1 -1
- data/lib/contrast/logger/cef_log.rb +151 -0
- data/lib/contrast/tasks/config.rb +90 -3
- 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/class_util.rb +3 -12
- data/lib/contrast/utils/hash_digest.rb +14 -6
- data/lib/contrast/utils/input_classification.rb +73 -0
- data/lib/contrast/utils/log_utils.rb +114 -0
- data/lib/contrast/utils/middleware_utils.rb +9 -9
- data/lib/contrast/utils/net_http_base.rb +13 -10
- data/lib/contrast/utils/object_share.rb +2 -1
- data/lib/contrast/utils/os.rb +0 -5
- data/lib/contrast/utils/patching/policy/patch_utils.rb +4 -9
- data/lib/contrast/utils/response_utils.rb +18 -33
- data/lib/contrast/utils/telemetry.rb +1 -1
- data/lib/contrast/utils/telemetry_client.rb +1 -1
- data/lib/contrast/utils/telemetry_identifier.rb +1 -1
- data/lib/contrast.rb +4 -3
- data/resources/assess/policy.json +98 -0
- data/resources/deadzone/policy.json +0 -86
- data/ruby-agent.gemspec +9 -8
- data/service_executables/VERSION +1 -1
- data/service_executables/linux/contrast-service +0 -0
- data/service_executables/mac/contrast-service +0 -0
- metadata +103 -38
- data/lib/contrast/agent/assess/rule/response/cachecontrol_rule.rb +0 -184
- data/lib/contrast/agent/assess/rule/response/clickjacking_rule.rb +0 -66
- data/lib/contrast/agent/assess/rule/response/x_content_type_rule.rb +0 -52
- data/lib/contrast/agent/assess/rule/response/x_xss_protection_rule.rb +0 -53
- data/lib/contrast/extension/kernel.rb +0 -54
@@ -3,6 +3,7 @@
|
|
3
3
|
|
4
4
|
#include "cs__contrast_patch.h"
|
5
5
|
#include "../cs__common/cs__common.h"
|
6
|
+
#include "../cs__scope/cs__scope.h"
|
6
7
|
#include <ruby.h>
|
7
8
|
|
8
9
|
VALUE build_preshift(const VALUE method_policy, const VALUE object,
|
@@ -34,25 +35,29 @@ VALUE contrast_patch_call_original(const VALUE *args) {
|
|
34
35
|
method = args[3];
|
35
36
|
method_id = SYM2ID(method);
|
36
37
|
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
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
|
56
61
|
}
|
57
62
|
|
58
63
|
VALUE contrast_call_pre_patch(const VALUE method_policy, const VALUE method,
|
@@ -84,15 +89,22 @@ VALUE contrast_call_post_patch(const VALUE method_policy, const VALUE preshift,
|
|
84
89
|
method_policy, preshift, object, ret, send, block);
|
85
90
|
}
|
86
91
|
|
87
|
-
|
88
|
-
|
89
|
-
VALUE exception
|
90
|
-
VALUE *argv;
|
91
|
-
|
92
|
+
/* wrap rb_ensure so we can rescue an exception */
|
93
|
+
VALUE rescue_func(VALUE arg1) {
|
94
|
+
VALUE exception;
|
92
95
|
/* rb_errinfo() gives the value of $!, the exception that
|
93
96
|
* triggered a rescue block.
|
94
97
|
*/
|
95
98
|
exception = rb_errinfo();
|
99
|
+
rb_exc_raise(exception);
|
100
|
+
|
101
|
+
return Qnil;
|
102
|
+
}
|
103
|
+
|
104
|
+
VALUE contrast_patch_call_ensure(const VALUE *args) {
|
105
|
+
int argc;
|
106
|
+
VALUE object, preshift, method_policy, method;
|
107
|
+
VALUE *argv;
|
96
108
|
|
97
109
|
object = args[0];
|
98
110
|
method = args[1];
|
@@ -103,12 +115,20 @@ VALUE contrast_patch_call_rescue(const VALUE *args) {
|
|
103
115
|
|
104
116
|
contrast_call_post_patch(method_policy, preshift, object, Qnil, argc, argv);
|
105
117
|
|
106
|
-
/* reraise the exception that got us here */
|
107
|
-
rb_exc_raise(exception);
|
108
|
-
|
109
118
|
return Qnil;
|
110
119
|
}
|
111
120
|
|
121
|
+
VALUE ensure_wrapper(const VALUE *args) {
|
122
|
+
VALUE original_method, original_args, ensure_args;
|
123
|
+
|
124
|
+
original_method = args[0];
|
125
|
+
original_args = (VALUE)args[1];
|
126
|
+
ensure_args = (VALUE)args[2];
|
127
|
+
|
128
|
+
return rb_ensure(original_method, original_args, contrast_patch_call_ensure,
|
129
|
+
(VALUE)ensure_args);
|
130
|
+
}
|
131
|
+
|
112
132
|
VALUE contrast_call_super(const VALUE *args) {
|
113
133
|
int argc;
|
114
134
|
VALUE *argv;
|
@@ -119,10 +139,12 @@ VALUE contrast_call_super(const VALUE *args) {
|
|
119
139
|
}
|
120
140
|
|
121
141
|
VALUE contrast_run_patches(const VALUE *wrapped_args) {
|
122
|
-
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;
|
123
144
|
int argc;
|
124
145
|
VALUE *argv;
|
125
|
-
VALUE
|
146
|
+
VALUE ensure_args[6];
|
147
|
+
VALUE rescue_wrapper_args[3];
|
126
148
|
|
127
149
|
impl = wrapped_args[0];
|
128
150
|
original_args = wrapped_args[1];
|
@@ -132,18 +154,22 @@ VALUE contrast_run_patches(const VALUE *wrapped_args) {
|
|
132
154
|
argc = NUM2INT(wrapped_args[5]);
|
133
155
|
argv = (VALUE *)wrapped_args[6];
|
134
156
|
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
157
|
+
rescue_wrapper_args[0] = contrast_patch_call_original;
|
158
|
+
rescue_wrapper_args[1] = original_args;
|
159
|
+
rescue_wrapper_args[2] = ensure_args;
|
160
|
+
|
161
|
+
ensure_args[0] = object;
|
162
|
+
ensure_args[1] = method;
|
163
|
+
ensure_args[2] = INT2NUM(argc);
|
164
|
+
ensure_args[3] = (VALUE)argv;
|
165
|
+
ensure_args[4] = method_policy;
|
140
166
|
|
141
167
|
/* Tracking, triggering, and propagation here. */
|
142
168
|
contrast_call_pre_patch(method_policy, method, object, argc, argv, Qnil);
|
143
169
|
|
144
170
|
/* Capture pre-call state */
|
145
171
|
preshift = build_preshift(method_policy, object, argc, argv);
|
146
|
-
|
172
|
+
ensure_args[5] = preshift;
|
147
173
|
|
148
174
|
/* We wrap a call to the original method with a rescue block, and we use
|
149
175
|
* rb_rescue2 to capture all Exception-inheriting exceptions (and if your
|
@@ -178,15 +204,14 @@ VALUE contrast_run_patches(const VALUE *wrapped_args) {
|
|
178
204
|
switch (impl) {
|
179
205
|
case IMPL_ALIAS_INSTANCE:
|
180
206
|
case IMPL_ALIAS_SINGLETON:
|
181
|
-
original_ret =
|
182
|
-
|
183
|
-
(VALUE)rescue_args, rb_eException, 0);
|
207
|
+
original_ret =
|
208
|
+
rb_rescue(ensure_wrapper, rescue_wrapper_args, rescue_func, Qnil);
|
184
209
|
break;
|
185
210
|
case IMPL_PREPEND_INSTANCE:
|
186
211
|
case IMPL_PREPEND_SINGLETON:
|
187
|
-
|
188
|
-
|
189
|
-
|
212
|
+
rescue_wrapper_args[0] = contrast_call_super;
|
213
|
+
original_ret =
|
214
|
+
rb_rescue(ensure_wrapper, rescue_wrapper_args, rescue_func, Qnil);
|
190
215
|
break;
|
191
216
|
};
|
192
217
|
|
@@ -214,8 +239,10 @@ VALUE contrast_run_patches(const VALUE *wrapped_args) {
|
|
214
239
|
|
215
240
|
VALUE contrast_ensure_function(const VALUE method_policy) {
|
216
241
|
/* exit scope */
|
217
|
-
rb_funcall(
|
218
|
-
|
242
|
+
VALUE scopes = rb_funcall(method_policy, rb_sym_scopes_to_exit, 0);
|
243
|
+
|
244
|
+
inst_methods_exit_method_scope(contrast_patcher(), scopes);
|
245
|
+
inst_methods_exit_cntr_scope(contrast_patcher(), 0);
|
219
246
|
|
220
247
|
return Qnil;
|
221
248
|
}
|
@@ -235,10 +262,10 @@ VALUE contrast_patch_dispatch(const int argc, const VALUE *argv,
|
|
235
262
|
* which is unnecessary, or run Contrast analysis on Contrast code,
|
236
263
|
* which will never terminate.
|
237
264
|
*/
|
238
|
-
nested_scope =
|
265
|
+
nested_scope = inst_methods_in_cntr_scope(contrast_patcher(), 0);
|
239
266
|
|
240
267
|
/* enter scope */
|
241
|
-
|
268
|
+
inst_methods_enter_cntr_scope(contrast_patcher(), 0);
|
242
269
|
|
243
270
|
/* Get the name of the calling method */
|
244
271
|
method = rb_funcall(object, rb_sym_method, 0);
|
@@ -253,9 +280,9 @@ VALUE contrast_patch_dispatch(const int argc, const VALUE *argv,
|
|
253
280
|
rb_funcall(patch_status, rb_sym_info_for, 3, object, method, Qtrue);
|
254
281
|
break;
|
255
282
|
case IMPL_PREPEND_SINGLETON:
|
256
|
-
|
257
|
-
|
258
|
-
|
283
|
+
known = rb_funcall(patch_status, rb_sym_info_for, 3, object, method,
|
284
|
+
Qfalse);
|
285
|
+
break;
|
259
286
|
case IMPL_ALIAS_SINGLETON:
|
260
287
|
known = rb_funcall(patch_status, rb_sym_info_for, 3, object, method,
|
261
288
|
Qfalse);
|
@@ -270,7 +297,7 @@ VALUE contrast_patch_dispatch(const int argc, const VALUE *argv,
|
|
270
297
|
}
|
271
298
|
|
272
299
|
/* Check conditions for not doing Contrast analysis */
|
273
|
-
if (nested_scope) {
|
300
|
+
if (nested_scope == Qtrue) {
|
274
301
|
/* if we were in scope */
|
275
302
|
do_contrast = 0;
|
276
303
|
} else if (!RTEST(known)) {
|
@@ -299,7 +326,9 @@ VALUE contrast_patch_dispatch(const int argc, const VALUE *argv,
|
|
299
326
|
}
|
300
327
|
|
301
328
|
/* Enter any scopes specific to method policy */
|
302
|
-
rb_funcall(
|
329
|
+
VALUE scopes = rb_funcall(method_policy, rb_sym_scopes_to_enter, 0);
|
330
|
+
|
331
|
+
inst_methods_enter_method_scope(contrast_patcher(), scopes);
|
303
332
|
|
304
333
|
/* If we're not doing Contrast analysis, exit scope and treat as normal. */
|
305
334
|
if (!do_contrast) {
|
@@ -316,14 +345,14 @@ VALUE contrast_patch_dispatch(const int argc, const VALUE *argv,
|
|
316
345
|
wrapped_args[5] = INT2NUM(argc);
|
317
346
|
wrapped_args[6] = (VALUE)argv;
|
318
347
|
|
319
|
-
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);
|
320
350
|
|
321
351
|
call_original:
|
322
352
|
|
323
353
|
/* exit scope */
|
324
354
|
contrast_ensure_function(method_policy);
|
325
355
|
|
326
|
-
|
327
356
|
switch (impl) {
|
328
357
|
case IMPL_ALIAS_INSTANCE:
|
329
358
|
case IMPL_ALIAS_SINGLETON:
|
@@ -345,19 +374,22 @@ VALUE contrast_alias_singleton_patch(const int argc, const VALUE *argv,
|
|
345
374
|
}
|
346
375
|
|
347
376
|
VALUE contrast_prepend_instance_patch(const int argc, const VALUE *argv,
|
348
|
-
|
377
|
+
const VALUE object) {
|
349
378
|
return contrast_patch_dispatch(argc, argv, IMPL_PREPEND_INSTANCE, object);
|
350
379
|
}
|
351
380
|
|
352
381
|
VALUE contrast_prepend_singleton_patch(const int argc, const VALUE *argv,
|
353
|
-
|
382
|
+
const VALUE object) {
|
354
383
|
return contrast_patch_dispatch(argc, argv, IMPL_PREPEND_SINGLETON, object);
|
355
384
|
}
|
356
385
|
|
357
|
-
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,
|
358
388
|
const VALUE cs_method) {
|
359
|
-
const VALUE original_method_name =
|
360
|
-
|
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);
|
361
393
|
char *cStr;
|
362
394
|
VALUE str;
|
363
395
|
rb_funcall(patch_status, rb_sym_set_info_for, 5, clazz,
|
@@ -423,8 +455,8 @@ VALUE contrast_patch_prepend(const VALUE self, const VALUE originalModule,
|
|
423
455
|
const VALUE is_instance_method =
|
424
456
|
rb_funcall(method_policy, rb_sym_instance_method, 0);
|
425
457
|
|
426
|
-
// Set the value for instance or singleton method
|
427
|
-
if (RTEST(is_instance_method)){
|
458
|
+
// Set the value for instance or singleton method
|
459
|
+
if (RTEST(is_instance_method)) {
|
428
460
|
rb_funcall(patch_status, rb_sym_set_info_for, 5, originalModule,
|
429
461
|
original_method_name, method_policy, instance, Qnil);
|
430
462
|
|
@@ -441,17 +473,19 @@ VALUE contrast_patch_prepend(const VALUE self, const VALUE originalModule,
|
|
441
473
|
rb_define_private_method(module, cMethodName,
|
442
474
|
contrast_prepend_instance_patch, -1);
|
443
475
|
} else {
|
444
|
-
rb_define_method(module, cMethodName,
|
476
|
+
rb_define_method(module, cMethodName,
|
477
|
+
contrast_prepend_instance_patch, -1);
|
445
478
|
}
|
446
479
|
} else {
|
447
|
-
rb_define_singleton_method(module, cMethodName,
|
448
|
-
-1);
|
480
|
+
rb_define_singleton_method(module, cMethodName,
|
481
|
+
contrast_prepend_singleton_patch, -1);
|
449
482
|
}
|
450
483
|
rb_prepend_module(originalModule, module);
|
451
484
|
|
452
485
|
if (rb_ver_below_three()) {
|
453
486
|
VALUE module_at;
|
454
|
-
VALUE rb_incl_in_mod_ary =
|
487
|
+
VALUE rb_incl_in_mod_ary =
|
488
|
+
rb_funcall(originalModule, rb_intern("included_in"), 0);
|
455
489
|
if (RB_TYPE_P(rb_incl_in_mod_ary, T_ARRAY)) {
|
456
490
|
int i = 0;
|
457
491
|
int size = rb_funcall(rb_incl_in_mod_ary, rb_intern("length"), 0);
|
@@ -462,7 +496,7 @@ VALUE contrast_patch_prepend(const VALUE self, const VALUE originalModule,
|
|
462
496
|
}
|
463
497
|
}
|
464
498
|
}
|
465
|
-
|
499
|
+
}
|
466
500
|
return Qtrue;
|
467
501
|
}
|
468
502
|
|
@@ -488,6 +522,8 @@ void Init_cs__contrast_patch(void) {
|
|
488
522
|
|
489
523
|
rb_sym_enter_method_scope = rb_intern("enter_method_scope!");
|
490
524
|
rb_sym_exit_method_scope = rb_intern("exit_method_scope!");
|
525
|
+
rb_sym_scopes_to_enter = rb_intern("scopes_to_enter");
|
526
|
+
rb_sym_scopes_to_exit = rb_intern("scopes_to_exit");
|
491
527
|
|
492
528
|
rb_define_module_function(contrast_patcher(), "contrast_define_method",
|
493
529
|
contrast_patch_define_method, 3);
|
@@ -18,6 +18,8 @@ static VALUE rb_sym_cs_to_s;
|
|
18
18
|
|
19
19
|
static VALUE rb_sym_enter_method_scope;
|
20
20
|
static VALUE rb_sym_exit_method_scope;
|
21
|
+
static VALUE rb_sym_scopes_to_enter;
|
22
|
+
static VALUE rb_sym_scopes_to_exit;
|
21
23
|
|
22
24
|
static VALUE rb_sym_build_method_name;
|
23
25
|
static VALUE rb_sym_info_for;
|
@@ -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
|
}
|