contrast-agent 5.3.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 +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_string/cs__assess_string.c +13 -1
- data/ext/cs__common/cs__common.c +12 -11
- data/ext/cs__contrast_patch/cs__contrast_patch.c +54 -43
- data/ext/cs__os_information/cs__os_information.c +13 -10
- data/ext/cs__scope/cs__scope.c +146 -97
- 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/propagator/buffer.rb +118 -0
- 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/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 +3 -1
- data/lib/contrast/agent/assess/property/tagged.rb +1 -1
- data/lib/contrast/agent/assess/rule/response/auto_complete_rule.rb +1 -1
- data/lib/contrast/agent/assess/rule/response/body_rule.rb +3 -3
- data/lib/contrast/agent/assess/rule/response/cache_control_header_rule.rb +1 -1
- data/lib/contrast/agent/assess/rule/response/parameters_pollution_rule.rb +1 -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/middleware.rb +3 -1
- data/lib/contrast/agent/patching/policy/patcher.rb +3 -3
- 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 +61 -8
- 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 +37 -5
- data/lib/contrast/agent/protect/rule/base_service.rb +3 -1
- data/lib/contrast/agent/protect/rule/cmd_injection.rb +13 -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/http_method_tampering/http_method_tampering_input_classification.rb +96 -0
- data/lib/contrast/agent/protect/rule/http_method_tampering.rb +8 -0
- data/lib/contrast/agent/protect/rule/no_sqli/no_sqli_input_classification.rb +231 -0
- data/lib/contrast/agent/protect/rule/no_sqli.rb +27 -0
- data/lib/contrast/agent/protect/rule/sqli/sqli_input_classification.rb +18 -54
- data/lib/contrast/agent/protect/rule/sqli/sqli_worth_watching.rb +1 -4
- 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/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 +246 -0
- data/lib/contrast/agent/reporting/masker/masker_utils.rb +58 -0
- data/lib/contrast/agent/reporting/report.rb +2 -0
- data/lib/contrast/agent/reporting/reporter.rb +23 -11
- 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 +1 -1
- 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/preflight_message.rb +2 -1
- 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_utilities/reporter_client.rb +16 -5
- data/lib/contrast/agent/reporting/reporting_utilities/reporter_client_utils.rb +27 -26
- 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 +68 -6
- data/lib/contrast/agent/reporting/reporting_utilities/response_handler_mode.rb +63 -0
- data/lib/contrast/agent/reporting/reporting_utilities/response_handler_utils.rb +122 -96
- 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 +1 -1
- data/lib/contrast/agent/request_context_extend.rb +1 -1
- data/lib/contrast/agent/request_handler.rb +4 -0
- 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/response_type.rb +30 -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/protect.rb +2 -2
- data/lib/contrast/components/sampling.rb +7 -11
- data/lib/contrast/components/settings.rb +106 -8
- data/lib/contrast/config/agent_configuration.rb +13 -30
- data/lib/contrast/config/api_configuration.rb +4 -67
- data/lib/contrast/config/api_proxy_configuration.rb +2 -45
- data/lib/contrast/config/application_configuration.rb +9 -84
- data/lib/contrast/config/assess_configuration.rb +10 -69
- data/lib/contrast/config/assess_rules_configuration.rb +9 -38
- data/lib/contrast/config/base_configuration.rb +17 -50
- data/lib/contrast/config/certification_configuration.rb +6 -63
- data/lib/contrast/config/exception_configuration.rb +5 -52
- data/lib/contrast/config/heap_dump_configuration.rb +6 -64
- data/lib/contrast/config/inventory_configuration.rb +2 -49
- data/lib/contrast/config/logger_configuration.rb +0 -36
- data/lib/contrast/config/protect_configuration.rb +17 -7
- data/lib/contrast/config/protect_rule_configuration.rb +12 -30
- data/lib/contrast/config/protect_rules_configuration.rb +21 -26
- data/lib/contrast/config/request_audit_configuration.rb +6 -48
- data/lib/contrast/config/root_configuration.rb +52 -12
- data/lib/contrast/config/ruby_configuration.rb +0 -36
- data/lib/contrast/config/sampling_configuration.rb +1 -57
- data/lib/contrast/config/server_configuration.rb +0 -36
- data/lib/contrast/config/service_configuration.rb +5 -44
- data/lib/contrast/configuration.rb +2 -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 +1 -1
- 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/input_classification.rb +73 -0
- data/lib/contrast/utils/log_utils.rb +1 -1
- data/lib/contrast/utils/middleware_utils.rb +9 -8
- data/lib/contrast/utils/net_http_base.rb +1 -1
- 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 -5
- 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/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 +73 -28
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 47aa135a205e4a74d64b778ae543f892213ca70e47be654032147a8bfe16dc82
|
4
|
+
data.tar.gz: 60f0de0e2675578bfb735c4f90303748bdc5e2053f2722dac4907bf84364d2f9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fdd2d1209de7366f810cb1d7355700a54cd7d7749d94736213cf96c47b8e5cedad449ec0dc2ab09753c0ecc3d064498d18d1d001edc5d998c6c615c4cd05b571
|
7
|
+
data.tar.gz: 888016b33c67e7f2f77f320affcd1e945a7cc6e1c01c87d559d231cbed3309bbd4fff74833a5296f21680492955977d042594a39d807d4cb91eecd6adc4b4636
|
@@ -22,7 +22,9 @@ static VALUE contrast_assess_array_join(const int argc, const VALUE *argv,
|
|
22
22
|
}
|
23
23
|
/* Finally, default to empty String. Implicit since nil.to_s is ''*/
|
24
24
|
|
25
|
+
/* call the Array.join but patched one */
|
25
26
|
result = rb_funcall2(ary, rb_sym_assess_array_join, argc, argv);
|
27
|
+
/* call the Contrast::Extensions::Assess::ArrayPropagator#cs__track_join */
|
26
28
|
result = rb_funcall(array_propagator, rb_sym_assess_track_array_join, 3,
|
27
29
|
ary, sep, result);
|
28
30
|
|
@@ -33,6 +35,11 @@ void Init_cs__assess_array(void) {
|
|
33
35
|
array_propagator =
|
34
36
|
rb_define_class_under(core_assess, "ArrayPropagator", rb_cObject);
|
35
37
|
rb_sym_assess_track_array_join = rb_intern("cs__track_join");
|
38
|
+
/*
|
39
|
+
* Here we need to check before using the alias or prepend spec
|
40
|
+
* This patch is happening here, we register the cs__track_join
|
41
|
+
* method of the Array propagator, and call it here from Ruby.
|
42
|
+
*/
|
36
43
|
rb_sym_assess_array_join =
|
37
44
|
contrast_register_patch("Array", "join", contrast_assess_array_join);
|
38
45
|
}
|
@@ -3,8 +3,20 @@
|
|
3
3
|
|
4
4
|
#include "cs__assess_basic_object.h"
|
5
5
|
#include "../cs__common/cs__common.h"
|
6
|
+
#include "../cs__scope/cs__scope.h"
|
6
7
|
#include <ruby.h>
|
7
8
|
|
9
|
+
/*
|
10
|
+
* Source code of instance_eval:
|
11
|
+
*
|
12
|
+
* static VALUE
|
13
|
+
* rb_obj_instance_eval_internal(int argc, const VALUE *argv, VALUE self)
|
14
|
+
* {
|
15
|
+
* VALUE klass = singleton_class_for_eval(self);
|
16
|
+
* return specific_eval(argc, argv, klass, self, RB_PASS_CALLED_KEYWORDS);
|
17
|
+
* }
|
18
|
+
*/
|
19
|
+
|
8
20
|
void contrast_assess_instance_eval_trigger_check(VALUE self, VALUE source,
|
9
21
|
VALUE ret) {
|
10
22
|
rb_funcall(basic_eval_trigger, instance_trigger_check_method, 3, self,
|
@@ -19,19 +31,21 @@ contrast_assess_basic_object_instance_eval(const int argc, const VALUE *argv,
|
|
19
31
|
return rb_obj_instance_eval(argc, argv, self);
|
20
32
|
}
|
21
33
|
|
22
|
-
|
23
|
-
RTEST(rb_funcall(contrast_patcher(), rb_sym_in_scope, 0));
|
34
|
+
VALUE nested_scope = inst_methods_in_cntr_scope(contrast_patcher(), 0);
|
24
35
|
|
25
|
-
|
36
|
+
/* Enter scope */
|
37
|
+
inst_methods_enter_cntr_scope(contrast_patcher(), 0);
|
26
38
|
|
39
|
+
/* Call the source: */
|
27
40
|
VALUE ret = rb_obj_instance_eval(argc, argv, self);
|
28
41
|
|
29
|
-
if (
|
42
|
+
if (nested_scope == Qfalse && argc > 0) {
|
30
43
|
VALUE data = argv[0];
|
31
44
|
contrast_assess_instance_eval_trigger_check(self, data, ret);
|
32
45
|
}
|
33
46
|
|
34
|
-
|
47
|
+
/* Exit scope */
|
48
|
+
inst_methods_exit_cntr_scope(contrast_patcher(), 0);
|
35
49
|
|
36
50
|
return ret;
|
37
51
|
}
|
@@ -30,7 +30,7 @@ VALUE rb_fiber_new_hook(VALUE (*func)(ANYARGS), VALUE obj) {
|
|
30
30
|
ID meth;
|
31
31
|
};
|
32
32
|
|
33
|
-
/*
|
33
|
+
/* underlying object is first entry in Enumerator struct def.
|
34
34
|
* that's all statically defined w/in enumerator.c, so we can't
|
35
35
|
* reference the data types and be safe about it. (yippee.)
|
36
36
|
* we cut out the TypedData_Get_Struct middleman & just go for it.
|
@@ -17,7 +17,6 @@ static VALUE contrast_assess_hash_bracket_constructor(const int argc,
|
|
17
17
|
const VALUE hash) {
|
18
18
|
VALUE result;
|
19
19
|
|
20
|
-
|
21
20
|
/* Array of Arrays: Hash[ [ [key, value], ... ] ] -> new_hash */
|
22
21
|
if (RB_TYPE_P(argv[0], T_ARRAY)) {
|
23
22
|
int i;
|
@@ -34,13 +33,13 @@ static VALUE contrast_assess_hash_bracket_constructor(const int argc,
|
|
34
33
|
}
|
35
34
|
}
|
36
35
|
|
37
|
-
const VALUE *
|
36
|
+
const VALUE *argv_final = argv;
|
38
37
|
/* unhandled case - shouldn't need it since issue is only unfrozen
|
39
38
|
* String keys
|
40
39
|
* # Hash[ object ] -> new_hash
|
41
40
|
*/
|
42
|
-
result =
|
43
|
-
|
41
|
+
result = rb_funcall2(hash, rb_sym_assess_hash_bracket_constructor, argc,
|
42
|
+
argv_final);
|
44
43
|
|
45
44
|
return result;
|
46
45
|
}
|
@@ -9,8 +9,7 @@
|
|
9
9
|
VALUE
|
10
10
|
contrast_patched_kernel_exec(const int argc, const VALUE *argv,
|
11
11
|
const VALUE self) {
|
12
|
-
|
13
|
-
inst_methods_in_cntr_scope(contrast_patcher(), 0);
|
12
|
+
VALUE nested_scope = inst_methods_in_cntr_scope(contrast_patcher(), 0);
|
14
13
|
|
15
14
|
if (nested_scope == Qfalse && argc > 0) {
|
16
15
|
/* enter scope */
|
@@ -5,36 +5,50 @@
|
|
5
5
|
#include "../cs__common/cs__common.h"
|
6
6
|
#include <ruby.h>
|
7
7
|
|
8
|
-
|
9
|
-
|
8
|
+
/*
|
9
|
+
* Marshal#load source:
|
10
|
+
* static VALUE
|
11
|
+
* marshal_load(int argc, VALUE *argv)
|
12
|
+
* {
|
13
|
+
* VALUE port, proc;
|
14
|
+
*
|
15
|
+
* rb_check_arity(argc, 1, 2);
|
16
|
+
* port = argv[0];
|
17
|
+
* proc = argc > 1 ? argv[1] : Qnil;
|
18
|
+
* return rb_marshal_load_with_proc(port, proc);
|
19
|
+
* }
|
20
|
+
*/
|
21
|
+
static VALUE contrast_marshal_module_load(const int argc, const VALUE *argv) {
|
10
22
|
VALUE result;
|
11
23
|
VALUE source_string;
|
12
24
|
|
13
|
-
|
25
|
+
/* Our patches need to apply only in the case where there was valid input.
|
26
|
+
*/
|
14
27
|
if (argc >= 1) {
|
15
28
|
source_string = argv[0];
|
16
29
|
} else {
|
17
30
|
source_string = Qnil;
|
18
31
|
}
|
19
32
|
|
20
|
-
|
33
|
+
/* Run our protect code ahead of the original method */
|
21
34
|
if (source_string != Qnil) {
|
22
|
-
rb_funcall(marshal_propagator, rb_sym_protect_marshal_load, 1,
|
35
|
+
rb_funcall(marshal_propagator, rb_sym_protect_marshal_load, 1,
|
36
|
+
source_string);
|
23
37
|
}
|
24
38
|
|
25
|
-
|
39
|
+
/* Invoke the original method */
|
26
40
|
result = rb_call_super(argc, argv);
|
27
41
|
|
28
|
-
|
42
|
+
/* Run our assess code after the original method */
|
29
43
|
if (source_string != Qnil) {
|
30
44
|
VALUE tracked =
|
31
45
|
rb_funcall(properties_hash, rb_sym_hash_tracked, 1, source_string);
|
32
46
|
|
33
|
-
|
47
|
+
/* Assuming the source is tracked and needs assess checks */
|
34
48
|
if (tracked == Qtrue) {
|
35
49
|
VALUE skip =
|
36
50
|
rb_funcall(contrast_patcher(), rb_sym_skip_assess_analysis, 0);
|
37
|
-
|
51
|
+
/* And Assess is enabled and applies to this request */
|
38
52
|
if (skip == Qfalse) {
|
39
53
|
rb_funcall(marshal_propagator, rb_sym_assess_marshal_load, 2,
|
40
54
|
source_string, result);
|
@@ -45,7 +59,7 @@ static VALUE contrast_marshal_module_load(const int argc,
|
|
45
59
|
}
|
46
60
|
|
47
61
|
void Init_cs__assess_marshal_module(void) {
|
48
|
-
|
62
|
+
/* Contrast::Agent::Assess::Tracker::PROPERTIES_HASH */
|
49
63
|
VALUE tracker = rb_define_class_under(assess, "Tracker", rb_cObject);
|
50
64
|
properties_hash = rb_const_get(tracker, rb_intern("PROPERTIES_HASH"));
|
51
65
|
marshal_propagator =
|
@@ -53,6 +67,6 @@ void Init_cs__assess_marshal_module(void) {
|
|
53
67
|
rb_sym_assess_marshal_load = rb_intern("cs__load_assess");
|
54
68
|
rb_sym_protect_marshal_load = rb_intern("cs__load_protect");
|
55
69
|
|
56
|
-
contrast_register_singleton_prepend_patch(
|
57
|
-
|
70
|
+
contrast_register_singleton_prepend_patch("Marshal", "load",
|
71
|
+
&contrast_marshal_module_load);
|
58
72
|
}
|
@@ -13,7 +13,7 @@ void contrast_assess_eval_trigger_check(VALUE module, VALUE source, VALUE ret) {
|
|
13
13
|
}
|
14
14
|
|
15
15
|
int nested_scope = inst_methods_in_cntr_scope(contrast_patcher(), 0);
|
16
|
-
|
16
|
+
/* enter scope */
|
17
17
|
inst_methods_enter_cntr_scope(contrast_patcher(), 0);
|
18
18
|
|
19
19
|
if (nested_scope == Qfalse) {
|
@@ -5,6 +5,18 @@
|
|
5
5
|
#include "../cs__common/cs__common.h"
|
6
6
|
#include <ruby.h>
|
7
7
|
|
8
|
+
/*
|
9
|
+
* The -@ method source:
|
10
|
+
*
|
11
|
+
* static VALUE
|
12
|
+
* str_uminus(VALUE str)
|
13
|
+
* {
|
14
|
+
* if (!BARE_STRING_P(str) && !rb_obj_frozen_p(str)) {
|
15
|
+
* str = rb_str_dup(str);
|
16
|
+
* }
|
17
|
+
* return rb_fstring(str);
|
18
|
+
* }
|
19
|
+
*/
|
8
20
|
static VALUE contrast_assess_string_freeze(const int argc, VALUE *argv,
|
9
21
|
const VALUE obj) {
|
10
22
|
if (!OBJ_FROZEN(obj)) {
|
@@ -39,7 +51,7 @@ void Init_cs__assess_string(void) {
|
|
39
51
|
rb_sym_dup = rb_intern("dup");
|
40
52
|
rb_sym_freeze = rb_intern("freeze");
|
41
53
|
rb_sym_pre_freeze = rb_intern("pre_freeze");
|
42
|
-
|
54
|
+
/* Contrast::Agent::Assess::Tracker::PROPERTIES_HASH */
|
43
55
|
VALUE tracker = rb_define_class_under(assess, "Tracker", rb_cObject);
|
44
56
|
properties_hash = rb_const_get(tracker, rb_intern("PROPERTIES_HASH"));
|
45
57
|
|
data/ext/cs__common/cs__common.c
CHANGED
@@ -60,8 +60,7 @@ VALUE contrast_patcher() {
|
|
60
60
|
}
|
61
61
|
|
62
62
|
VALUE contrast_register_patch(const char *module_name, const char *method_name,
|
63
|
-
VALUE(c_fn)(const int, VALUE *,
|
64
|
-
const VALUE)) {
|
63
|
+
VALUE(c_fn)(const int, VALUE *, const VALUE)) {
|
65
64
|
return _contrast_register_patch(module_name, method_name, c_fn,
|
66
65
|
IMPL_ALIAS_INSTANCE);
|
67
66
|
}
|
@@ -75,17 +74,17 @@ VALUE contrast_register_singleton_patch(const char *module_name,
|
|
75
74
|
}
|
76
75
|
|
77
76
|
VALUE contrast_register_prepend_patch(const char *module_name,
|
78
|
-
|
79
|
-
|
80
|
-
|
77
|
+
const char *method_name,
|
78
|
+
VALUE(c_fn)(const int, VALUE *,
|
79
|
+
const VALUE)) {
|
81
80
|
return _contrast_register_patch(module_name, method_name, c_fn,
|
82
81
|
IMPL_PREPEND_INSTANCE);
|
83
82
|
}
|
84
83
|
|
85
84
|
VALUE contrast_register_singleton_prepend_patch(const char *module_name,
|
86
|
-
|
87
|
-
|
88
|
-
|
85
|
+
const char *method_name,
|
86
|
+
VALUE(c_fn)(const int, VALUE *,
|
87
|
+
const VALUE)) {
|
89
88
|
return _contrast_register_patch(module_name, method_name, c_fn,
|
90
89
|
IMPL_PREPEND_SINGLETON);
|
91
90
|
}
|
@@ -135,7 +134,7 @@ _contrast_register_patch(const char *module_name, const char *method_name,
|
|
135
134
|
case IMPL_PREPEND_INSTANCE:
|
136
135
|
impl = ID2SYM(rb_sym_prepend_instance);
|
137
136
|
case IMPL_PREPEND_SINGLETON:
|
138
|
-
|
137
|
+
impl = ID2SYM(rb_sym_prepend_singleton);
|
139
138
|
break;
|
140
139
|
}
|
141
140
|
|
@@ -146,8 +145,10 @@ _contrast_register_patch(const char *module_name, const char *method_name,
|
|
146
145
|
}
|
147
146
|
|
148
147
|
int rb_ver_below_three() {
|
149
|
-
|
150
|
-
|
148
|
+
int ruby_version =
|
149
|
+
FIX2INT(rb_funcall(rb_const_get(rb_cObject, rb_intern("RUBY_VERSION")),
|
150
|
+
rb_intern("to_i"), 0));
|
151
|
+
return ruby_version < 3;
|
151
152
|
}
|
152
153
|
|
153
154
|
void Init_cs__common(void) {
|
@@ -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,17 +473,19 @@ 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
491
|
int size = rb_funcall(rb_incl_in_mod_ary, rb_intern("length"), 0);
|
@@ -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
|
}
|