Sha256: 95c9874f3b9b7056ad3d7a3250eeb91237f540594c96c5480658a3c5f7ca718c

Contents?: true

Size: 1.33 KB

Versions: 7

Compression:

Stored size: 1.33 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 int argc, VALUE *argv,
                                              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) {
    rb_sym_dup = rb_intern("dup");
    rb_sym_freeze = rb_intern("freeze");

    rb_sym_assess_string_uminus = contrast_register_patch("String",
                                                          "-@",
                                                          &contrast_assess_string_uminus);
}

Version data entries

7 entries across 7 versions & 1 rubygems

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