Sha256: b52021edb1f9196a0930411a3eefd78c00eacda0a123aad4c54264f279672401

Contents?: true

Size: 1.8 KB

Versions: 6

Compression:

Stored size: 1.8 KB

Contents

/* Copyright (c) 2020 Contrast Security, Inc.  See
 * https://www.contrastsecurity.com/enduser-terms-0317a for more details. */

#include "cs__assess_basic_object.h"
#include "../cs__common/cs__common.h"
#include <ruby.h>

void contrast_assess_instance_eval_trigger_check(VALUE self, VALUE source,
                                                 VALUE ret) {
    rb_funcall(basic_eval_trigger, instance_trigger_check_method, 3, self, source, ret);
}

VALUE
contrast_assess_basic_object_instance_eval(const int argc, const VALUE *argv,
                                           const VALUE self) {

    if (RTEST(rb_funcall(contrast_patcher(), rb_sym_skip_assess_analysis, 0))) {
        return rb_obj_instance_eval(argc, argv, self);
    }

    int nested_scope =
        RTEST(rb_funcall(contrast_patcher(), rb_sym_in_scope, 0));

    rb_funcall(contrast_patcher(), rb_sym_enter_scope, 0);

    VALUE ret = rb_obj_instance_eval(argc, argv, self);

    if (!nested_scope && argc > 0) {
        VALUE data = argv[0];
        contrast_assess_instance_eval_trigger_check(self, data, ret);
    }

    rb_funcall(contrast_patcher(), rb_sym_exit_scope, 0);

    return ret;
}

void Init_cs__assess_basic_object(void) {
    basic_eval_trigger = rb_define_class_under(core_assess, "EvalTrigger", rb_cObject);
    instance_trigger_check_method = rb_intern("instance_eval_trigger_check");

    /* We don't keep a reference to the underlying method.
     * Instead, we call rb_obj_instance_eval directly.
     * This should work an overwhelming majority of the time,
     * but if someone else patched BasicObject#instance_eval,
     * IDK if this is intentional... noting it.  -ajm
     */
    contrast_register_patch("BasicObject",
                            "instance_eval",
                            contrast_assess_basic_object_instance_eval);

}

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
contrast-agent-3.13.2 ext/cs__assess_basic_object/cs__assess_basic_object.c
contrast-agent-3.13.1 ext/cs__assess_basic_object/cs__assess_basic_object.c
contrast-agent-3.13.0 ext/cs__assess_basic_object/cs__assess_basic_object.c
contrast-agent-3.12.2 ext/cs__assess_basic_object/cs__assess_basic_object.c
contrast-agent-3.12.1 ext/cs__assess_basic_object/cs__assess_basic_object.c
contrast-agent-3.12.0 ext/cs__assess_basic_object/cs__assess_basic_object.c