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.
Files changed (161) hide show
  1. checksums.yaml +4 -4
  2. data/ext/cs__assess_array/cs__assess_array.c +7 -0
  3. data/ext/cs__assess_basic_object/cs__assess_basic_object.c +19 -5
  4. data/ext/cs__assess_fiber_track/cs__assess_fiber_track.c +1 -1
  5. data/ext/cs__assess_hash/cs__assess_hash.c +3 -4
  6. data/ext/cs__assess_kernel/cs__assess_kernel.c +1 -2
  7. data/ext/cs__assess_marshal_module/cs__assess_marshal_module.c +26 -12
  8. data/ext/cs__assess_module/cs__assess_module.c +1 -1
  9. data/ext/cs__assess_string/cs__assess_string.c +13 -1
  10. data/ext/cs__common/cs__common.c +12 -11
  11. data/ext/cs__contrast_patch/cs__contrast_patch.c +54 -43
  12. data/ext/cs__os_information/cs__os_information.c +13 -10
  13. data/ext/cs__scope/cs__scope.c +146 -97
  14. data/lib/contrast/agent/assess/finalizers/hash.rb +2 -0
  15. data/lib/contrast/agent/assess/policy/policy_node.rb +50 -27
  16. data/lib/contrast/agent/assess/policy/policy_node_utils.rb +51 -0
  17. data/lib/contrast/agent/assess/policy/preshift.rb +8 -2
  18. data/lib/contrast/agent/assess/policy/propagation_method.rb +47 -13
  19. data/lib/contrast/agent/assess/policy/propagator/buffer.rb +118 -0
  20. data/lib/contrast/agent/assess/policy/propagator/keep.rb +19 -4
  21. data/lib/contrast/agent/assess/policy/propagator/remove.rb +18 -2
  22. data/lib/contrast/agent/assess/policy/propagator/splat.rb +17 -3
  23. data/lib/contrast/agent/assess/policy/propagator/substitution.rb +1 -1
  24. data/lib/contrast/agent/assess/policy/propagator/substitution_utils.rb +1 -1
  25. data/lib/contrast/agent/assess/policy/propagator/trim.rb +1 -1
  26. data/lib/contrast/agent/assess/policy/propagator.rb +1 -0
  27. data/lib/contrast/agent/assess/policy/source_method.rb +7 -7
  28. data/lib/contrast/agent/assess/policy/trigger_method.rb +3 -1
  29. data/lib/contrast/agent/assess/property/tagged.rb +1 -1
  30. data/lib/contrast/agent/assess/rule/response/auto_complete_rule.rb +1 -1
  31. data/lib/contrast/agent/assess/rule/response/body_rule.rb +3 -3
  32. data/lib/contrast/agent/assess/rule/response/cache_control_header_rule.rb +1 -1
  33. data/lib/contrast/agent/assess/rule/response/parameters_pollution_rule.rb +1 -1
  34. data/lib/contrast/agent/deadzone/policy/deadzone_node.rb +0 -7
  35. data/lib/contrast/agent/deadzone/policy/policy.rb +0 -6
  36. data/lib/contrast/agent/exclusion_matcher.rb +3 -3
  37. data/lib/contrast/agent/middleware.rb +3 -1
  38. data/lib/contrast/agent/patching/policy/patcher.rb +3 -3
  39. data/lib/contrast/agent/patching/policy/policy_node.rb +15 -2
  40. data/lib/contrast/agent/protect/exploitable_collection.rb +38 -0
  41. data/lib/contrast/agent/protect/input_analyzer/input_analyzer.rb +61 -8
  42. data/lib/contrast/agent/protect/policy/applies_no_sqli_rule.rb +2 -1
  43. data/lib/contrast/agent/protect/policy/applies_path_traversal_rule.rb +2 -2
  44. data/lib/contrast/agent/protect/rule/base.rb +37 -5
  45. data/lib/contrast/agent/protect/rule/base_service.rb +3 -1
  46. data/lib/contrast/agent/protect/rule/cmd_injection.rb +13 -0
  47. data/lib/contrast/agent/protect/rule/cmdi/cmdi_input_classification.rb +83 -0
  48. data/lib/contrast/agent/protect/rule/cmdi/cmdi_worth_watching.rb +64 -0
  49. data/lib/contrast/agent/protect/rule/http_method_tampering/http_method_tampering_input_classification.rb +96 -0
  50. data/lib/contrast/agent/protect/rule/http_method_tampering.rb +8 -0
  51. data/lib/contrast/agent/protect/rule/no_sqli/no_sqli_input_classification.rb +231 -0
  52. data/lib/contrast/agent/protect/rule/no_sqli.rb +27 -0
  53. data/lib/contrast/agent/protect/rule/sqli/sqli_input_classification.rb +18 -54
  54. data/lib/contrast/agent/protect/rule/sqli/sqli_worth_watching.rb +1 -4
  55. data/lib/contrast/agent/protect/rule/unsafe_file_upload/unsafe_file_upload_input_classification.rb +82 -0
  56. data/lib/contrast/agent/protect/rule/unsafe_file_upload/unsafe_file_upload_matcher.rb +45 -0
  57. data/lib/contrast/agent/protect/rule/unsafe_file_upload.rb +42 -0
  58. data/lib/contrast/agent/reporting/attack_result/attack_result.rb +63 -0
  59. data/lib/contrast/agent/reporting/attack_result/rasp_rule_sample.rb +52 -0
  60. data/lib/contrast/agent/reporting/attack_result/response_type.rb +29 -0
  61. data/lib/contrast/agent/reporting/attack_result/user_input.rb +87 -0
  62. data/lib/contrast/agent/reporting/masker/masker.rb +246 -0
  63. data/lib/contrast/agent/reporting/masker/masker_utils.rb +58 -0
  64. data/lib/contrast/agent/reporting/report.rb +2 -0
  65. data/lib/contrast/agent/reporting/reporter.rb +23 -11
  66. data/lib/contrast/agent/reporting/reporting_events/agent_startup.rb +30 -0
  67. data/lib/contrast/agent/reporting/reporting_events/application_inventory.rb +7 -3
  68. data/lib/contrast/agent/reporting/reporting_events/application_startup.rb +40 -0
  69. data/lib/contrast/agent/reporting/reporting_events/application_startup_instrumentation.rb +27 -0
  70. data/lib/contrast/agent/reporting/reporting_events/finding.rb +1 -1
  71. data/lib/contrast/agent/reporting/reporting_events/library_usage_observation.rb +5 -5
  72. data/lib/contrast/agent/reporting/reporting_events/observed_route.rb +9 -9
  73. data/lib/contrast/agent/reporting/reporting_events/preflight_message.rb +2 -1
  74. data/lib/contrast/agent/reporting/reporting_events/reporting_event.rb +2 -1
  75. data/lib/contrast/agent/reporting/reporting_events/route_coverage.rb +8 -6
  76. data/lib/contrast/agent/reporting/reporting_utilities/reporter_client.rb +16 -5
  77. data/lib/contrast/agent/reporting/reporting_utilities/reporter_client_utils.rb +27 -26
  78. data/lib/contrast/agent/reporting/reporting_utilities/reporting_storage.rb +1 -1
  79. data/lib/contrast/agent/reporting/reporting_utilities/response_extractor.rb +97 -0
  80. data/lib/contrast/agent/reporting/reporting_utilities/response_handler.rb +68 -6
  81. data/lib/contrast/agent/reporting/reporting_utilities/response_handler_mode.rb +63 -0
  82. data/lib/contrast/agent/reporting/reporting_utilities/response_handler_utils.rb +122 -96
  83. data/lib/contrast/agent/reporting/settings/application_settings.rb +9 -0
  84. data/lib/contrast/agent/reporting/settings/assess_server_feature.rb +5 -33
  85. data/lib/contrast/agent/reporting/settings/protect_server_feature.rb +1 -1
  86. data/lib/contrast/agent/reporting/settings/sampling.rb +36 -0
  87. data/lib/contrast/agent/reporting/settings/sensitive_data_masking.rb +110 -0
  88. data/lib/contrast/agent/reporting/settings/sensitive_data_masking_rule.rb +58 -0
  89. data/lib/contrast/agent/request_context.rb +1 -1
  90. data/lib/contrast/agent/request_context_extend.rb +1 -1
  91. data/lib/contrast/agent/request_handler.rb +4 -0
  92. data/lib/contrast/agent/telemetry/events/exceptions/telemetry_exception_base.rb +51 -0
  93. data/lib/contrast/agent/telemetry/events/exceptions/telemetry_exception_event.rb +36 -0
  94. data/lib/contrast/agent/telemetry/events/exceptions/telemetry_exception_message.rb +97 -0
  95. data/lib/contrast/agent/telemetry/events/exceptions/telemetry_exception_message_exception.rb +65 -0
  96. data/lib/contrast/agent/telemetry/events/exceptions/telemetry_exception_stack_frame.rb +47 -0
  97. data/lib/contrast/agent/{metric_telemetry_event.rb → telemetry/events/metric_telemetry_event.rb} +1 -1
  98. data/lib/contrast/agent/{startup_metrics_telemetry_event.rb → telemetry/events/startup_metrics_telemetry_event.rb} +3 -3
  99. data/lib/contrast/agent/{telemetry_event.rb → telemetry/events/telemetry_event.rb} +1 -1
  100. data/lib/contrast/agent/{telemetry.rb → telemetry/telemetry.rb} +32 -19
  101. data/lib/contrast/agent/thread_watcher.rb +1 -1
  102. data/lib/contrast/agent/version.rb +1 -1
  103. data/lib/contrast/agent.rb +3 -0
  104. data/lib/contrast/api/communication/speedracer.rb +1 -1
  105. data/lib/contrast/api/decorators/address.rb +1 -1
  106. data/lib/contrast/api/decorators/response_type.rb +30 -0
  107. data/lib/contrast/api/decorators.rb +1 -0
  108. data/lib/contrast/components/app_context.rb +0 -4
  109. data/lib/contrast/components/assess.rb +14 -0
  110. data/lib/contrast/components/protect.rb +2 -2
  111. data/lib/contrast/components/sampling.rb +7 -11
  112. data/lib/contrast/components/settings.rb +106 -8
  113. data/lib/contrast/config/agent_configuration.rb +13 -30
  114. data/lib/contrast/config/api_configuration.rb +4 -67
  115. data/lib/contrast/config/api_proxy_configuration.rb +2 -45
  116. data/lib/contrast/config/application_configuration.rb +9 -84
  117. data/lib/contrast/config/assess_configuration.rb +10 -69
  118. data/lib/contrast/config/assess_rules_configuration.rb +9 -38
  119. data/lib/contrast/config/base_configuration.rb +17 -50
  120. data/lib/contrast/config/certification_configuration.rb +6 -63
  121. data/lib/contrast/config/exception_configuration.rb +5 -52
  122. data/lib/contrast/config/heap_dump_configuration.rb +6 -64
  123. data/lib/contrast/config/inventory_configuration.rb +2 -49
  124. data/lib/contrast/config/logger_configuration.rb +0 -36
  125. data/lib/contrast/config/protect_configuration.rb +17 -7
  126. data/lib/contrast/config/protect_rule_configuration.rb +12 -30
  127. data/lib/contrast/config/protect_rules_configuration.rb +21 -26
  128. data/lib/contrast/config/request_audit_configuration.rb +6 -48
  129. data/lib/contrast/config/root_configuration.rb +52 -12
  130. data/lib/contrast/config/ruby_configuration.rb +0 -36
  131. data/lib/contrast/config/sampling_configuration.rb +1 -57
  132. data/lib/contrast/config/server_configuration.rb +0 -36
  133. data/lib/contrast/config/service_configuration.rb +5 -44
  134. data/lib/contrast/configuration.rb +2 -3
  135. data/lib/contrast/extension/assess/string.rb +20 -1
  136. data/lib/contrast/extension/module.rb +0 -1
  137. data/lib/contrast/framework/manager.rb +2 -2
  138. data/lib/contrast/logger/application.rb +1 -1
  139. data/lib/contrast/logger/cef_log.rb +1 -1
  140. data/lib/contrast/tasks/config.rb +90 -3
  141. data/lib/contrast/utils/assess/object_store.rb +36 -0
  142. data/lib/contrast/utils/assess/propagation_method_utils.rb +6 -0
  143. data/lib/contrast/utils/class_util.rb +3 -12
  144. data/lib/contrast/utils/input_classification.rb +73 -0
  145. data/lib/contrast/utils/log_utils.rb +1 -1
  146. data/lib/contrast/utils/middleware_utils.rb +9 -8
  147. data/lib/contrast/utils/net_http_base.rb +1 -1
  148. data/lib/contrast/utils/object_share.rb +2 -1
  149. data/lib/contrast/utils/os.rb +0 -5
  150. data/lib/contrast/utils/patching/policy/patch_utils.rb +4 -5
  151. data/lib/contrast/utils/response_utils.rb +18 -33
  152. data/lib/contrast/utils/telemetry.rb +1 -1
  153. data/lib/contrast/utils/telemetry_client.rb +1 -1
  154. data/lib/contrast/utils/telemetry_identifier.rb +1 -1
  155. data/resources/assess/policy.json +98 -0
  156. data/resources/deadzone/policy.json +0 -86
  157. data/ruby-agent.gemspec +9 -8
  158. data/service_executables/VERSION +1 -1
  159. data/service_executables/linux/contrast-service +0 -0
  160. data/service_executables/mac/contrast-service +0 -0
  161. metadata +73 -28
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: bfca6df4def9f2366f7a92651aa9cd2fc40f3ced6784228844d8025cee5a4850
4
- data.tar.gz: b66b10e1d892adee985f070963e08945fd9dd4faf641f4f06a8372683129facd
3
+ metadata.gz: 47aa135a205e4a74d64b778ae543f892213ca70e47be654032147a8bfe16dc82
4
+ data.tar.gz: 60f0de0e2675578bfb735c4f90303748bdc5e2053f2722dac4907bf84364d2f9
5
5
  SHA512:
6
- metadata.gz: '08a6989482a82249d3fb906b2f79788e03d5c5ffa03973beabe591292fa780cd2bd3a6f459e8b7eedf58181a729720da0e95b1afa069e8869511b6ff4338625d'
7
- data.tar.gz: b460cad0b10b3355bfafa3be8c49ba41d0174e5a5d0524bbab273cf51c3d9fed6348027b9658dd3dadddcace9012f0ce119566f46899ee71f8712aebf56a98bf
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
- int nested_scope =
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
- rb_funcall(contrast_patcher(), rb_sym_enter_scope, 0);
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 (!nested_scope && argc > 0) {
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
- rb_funcall(contrast_patcher(), rb_sym_exit_scope, 0);
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
- /* underlying object is first entry in Enumerator struct def.
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 * argv_final = argv;
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
- rb_funcall2(hash, rb_sym_assess_hash_bracket_constructor, argc, argv_final);
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
- int nested_scope =
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
- static VALUE contrast_marshal_module_load(const int argc,
9
- const VALUE *argv) {
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
- // Our patches only need only apply in the case where there was valid input.
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
- // Run our protect code ahead of the original method
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, source_string);
35
+ rb_funcall(marshal_propagator, rb_sym_protect_marshal_load, 1,
36
+ source_string);
23
37
  }
24
38
 
25
- // Invoke the original method
39
+ /* Invoke the original method */
26
40
  result = rb_call_super(argc, argv);
27
41
 
28
- // Run our assess code after the original method
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
- // Assuming the source is tracked and needs assess checks
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
- // And Assess is enabled and applies to this request
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
- // Contrast::Agent::Assess::Tracker::PROPERTIES_HASH
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
- "Marshal", "load", &contrast_marshal_module_load);
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
- /* enter scope */
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
- // Contrast::Agent::Assess::Tracker::PROPERTIES_HASH
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
 
@@ -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
- const char *method_name,
79
- VALUE(c_fn)(const int, VALUE *,
80
- const VALUE)) {
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
- const char *method_name,
87
- VALUE(c_fn)(const int, VALUE *,
88
- const VALUE)) {
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
- impl = ID2SYM(rb_sym_prepend_singleton);
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
- int ruby_version = FIX2INT(rb_funcall(rb_const_get(rb_cObject, rb_intern("RUBY_VERSION")), rb_intern("to_i"), 0));
150
- return ruby_version < 3;
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
- /* 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, rb_block_proc(), RB_PASS_CALLED_KEYWORDS);
46
- } else {
47
- return rb_funcallv_kw(object, method_id, argc, params, RB_PASS_CALLED_KEYWORDS);
48
- }
49
- /* Ruby < 2.7 */
50
- #else
51
- if (rb_block_given_p()) {
52
- return rb_funcall_with_block(object, method_id, argc, params, rb_block_proc());
53
- } else {
54
- return rb_funcall2(object, method_id, argc, params);
55
- }
56
- #endif
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
- return Qnil;
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
- return rb_ensure(original_method, original_args, contrast_patch_call_ensure, (VALUE)ensure_args);
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, preshift, transformed_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 = rb_rescue(ensure_wrapper, rescue_wrapper_args, rescue_func, Qnil);
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 = rb_rescue(ensure_wrapper, rescue_wrapper_args, rescue_func, Qnil);
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
- known =
276
- rb_funcall(patch_status, rb_sym_info_for, 3, object, method, Qfalse);
277
- break;
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, contrast_ensure_function, method_policy);
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
- const VALUE object) {
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
- const VALUE object) {
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, const VALUE method_policy,
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 = rb_funcall(method_policy, rb_sym_method_name, 0);
381
- const VALUE is_instance_method = rb_funcall(method_policy, rb_sym_instance_method, 0);
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, contrast_prepend_instance_patch, -1);
476
+ rb_define_method(module, cMethodName,
477
+ contrast_prepend_instance_patch, -1);
466
478
  }
467
479
  } else {
468
- rb_define_singleton_method(module, cMethodName, contrast_prepend_singleton_patch,
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 = rb_funcall(originalModule, rb_intern("included_in"), 0);
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 (&uname_pointer);
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"), rb_str_new2(uname_pointer.sysname));
19
- rb_hash_aset(rb_data_hash, rb_str_new2("os_version"), rb_str_new2(uname_pointer.release));
20
- rb_hash_aset(rb_data_hash, rb_str_new2("os_complete_version"), rb_str_new2(uname_pointer.version));
21
- rb_hash_aset(rb_data_hash, rb_str_new2("os_arch"), rb_str_new2(uname_pointer.machine));
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", contrast_get_system_information, 0);
32
+ rb_define_module_function(os, "get_system_information",
33
+ contrast_get_system_information, 0);
31
34
  }