Sha256: 738c63c3766b2b431b1683c2d514f6b5b0438f3d7818ce4c0e759daf0f72f1ee

Contents?: true

Size: 1.35 KB

Versions: 7

Compression:

Stored size: 1.35 KB

Contents

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

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

static VALUE contrast_assess_string_uminus(const VALUE obj) {
    VALUE dup, tracked;
    if (!OBJ_FROZEN(obj)) {
        tracked = rb_funcall(obj, rb_sym_cs_tracked, 0);
        if (RTEST(tracked)) {
            /*
             * If the object is not frozen and the object is tracked, we cheat.
             * We dup and then freeze to replicate the behavior of str_uminus in
             * string.c, but we ignore any other monkey patches on String#-@
             */
            dup = rb_funcall(obj, rb_sym_dup, 0);
            rb_funcall(dup, rb_sym_freeze, 0);
            return dup;
        }
    }
    /* in all other cases, preserve monkey patching and c call */
    return rb_funcall(obj, rb_sym_assess_string_uminus, 0);
}

void Init_cs__assess_string(void) {
    VALUE string_class;

    rb_sym_dup = rb_intern("dup");
    rb_sym_freeze = rb_intern("freeze");
    rb_sym_assess_string_uminus = rb_intern("cs__patched_minus_at");

    string_class = rb_define_class("String", rb_cObject);
    /* -@ */
    contrast_alias_method(string_class, "cs__patched_minus_at", "-@");
    rb_define_method(string_class, "-@", contrast_assess_string_uminus, 0);
}

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
contrast-agent-3.10.2 ext/cs__assess_string/cs__assess_string.c
contrast-agent-3.10.1 ext/cs__assess_string/cs__assess_string.c
contrast-agent-3.10.0 ext/cs__assess_string/cs__assess_string.c
contrast-agent-3.9.1 ext/cs__assess_string/cs__assess_string.c
contrast-agent-3.9.0 ext/cs__assess_string/cs__assess_string.c
contrast-agent-3.8.5 ext/cs__assess_string/cs__assess_string.c
contrast-agent-3.8.4 ext/cs__assess_string/cs__assess_string.c