nashorn/test/script/nosecurity/JDK-8060688.js
author jmanson
Tue, 12 May 2015 14:39:36 -0700
changeset 30445 e1e28b9abbe5
parent 27106 d2d7e511c05c
permissions -rw-r--r--
8079841: Buffer underflow with empty zip entry names Summary: check for zero-length entry name before accessing "last" byte Reviewed-by: sherman, martin
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
27106
d2d7e511c05c 8060688: Nashorn: Generated script class name fails --verify-code for names with special chars
sundar
parents:
diff changeset
     1
/*
d2d7e511c05c 8060688: Nashorn: Generated script class name fails --verify-code for names with special chars
sundar
parents:
diff changeset
     2
 * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
d2d7e511c05c 8060688: Nashorn: Generated script class name fails --verify-code for names with special chars
sundar
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
d2d7e511c05c 8060688: Nashorn: Generated script class name fails --verify-code for names with special chars
sundar
parents:
diff changeset
     4
 *
d2d7e511c05c 8060688: Nashorn: Generated script class name fails --verify-code for names with special chars
sundar
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
d2d7e511c05c 8060688: Nashorn: Generated script class name fails --verify-code for names with special chars
sundar
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
d2d7e511c05c 8060688: Nashorn: Generated script class name fails --verify-code for names with special chars
sundar
parents:
diff changeset
     7
 * published by the Free Software Foundation.
d2d7e511c05c 8060688: Nashorn: Generated script class name fails --verify-code for names with special chars
sundar
parents:
diff changeset
     8
 *
d2d7e511c05c 8060688: Nashorn: Generated script class name fails --verify-code for names with special chars
sundar
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
d2d7e511c05c 8060688: Nashorn: Generated script class name fails --verify-code for names with special chars
sundar
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
d2d7e511c05c 8060688: Nashorn: Generated script class name fails --verify-code for names with special chars
sundar
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
d2d7e511c05c 8060688: Nashorn: Generated script class name fails --verify-code for names with special chars
sundar
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
d2d7e511c05c 8060688: Nashorn: Generated script class name fails --verify-code for names with special chars
sundar
parents:
diff changeset
    13
 * accompanied this code).
d2d7e511c05c 8060688: Nashorn: Generated script class name fails --verify-code for names with special chars
sundar
parents:
diff changeset
    14
 *
d2d7e511c05c 8060688: Nashorn: Generated script class name fails --verify-code for names with special chars
sundar
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
d2d7e511c05c 8060688: Nashorn: Generated script class name fails --verify-code for names with special chars
sundar
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
d2d7e511c05c 8060688: Nashorn: Generated script class name fails --verify-code for names with special chars
sundar
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
d2d7e511c05c 8060688: Nashorn: Generated script class name fails --verify-code for names with special chars
sundar
parents:
diff changeset
    18
 *
d2d7e511c05c 8060688: Nashorn: Generated script class name fails --verify-code for names with special chars
sundar
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
d2d7e511c05c 8060688: Nashorn: Generated script class name fails --verify-code for names with special chars
sundar
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
d2d7e511c05c 8060688: Nashorn: Generated script class name fails --verify-code for names with special chars
sundar
parents:
diff changeset
    21
 * questions.
d2d7e511c05c 8060688: Nashorn: Generated script class name fails --verify-code for names with special chars
sundar
parents:
diff changeset
    22
 */
d2d7e511c05c 8060688: Nashorn: Generated script class name fails --verify-code for names with special chars
sundar
parents:
diff changeset
    23
d2d7e511c05c 8060688: Nashorn: Generated script class name fails --verify-code for names with special chars
sundar
parents:
diff changeset
    24
/**
d2d7e511c05c 8060688: Nashorn: Generated script class name fails --verify-code for names with special chars
sundar
parents:
diff changeset
    25
 * JDK-8060688: Nashorn: Generated script class name fails --verify-code for names with special chars
d2d7e511c05c 8060688: Nashorn: Generated script class name fails --verify-code for names with special chars
sundar
parents:
diff changeset
    26
 *
d2d7e511c05c 8060688: Nashorn: Generated script class name fails --verify-code for names with special chars
sundar
parents:
diff changeset
    27
 * @test
d2d7e511c05c 8060688: Nashorn: Generated script class name fails --verify-code for names with special chars
sundar
parents:
diff changeset
    28
 * @run
d2d7e511c05c 8060688: Nashorn: Generated script class name fails --verify-code for names with special chars
sundar
parents:
diff changeset
    29
 */
d2d7e511c05c 8060688: Nashorn: Generated script class name fails --verify-code for names with special chars
sundar
parents:
diff changeset
    30
d2d7e511c05c 8060688: Nashorn: Generated script class name fails --verify-code for names with special chars
sundar
parents:
diff changeset
    31
var NashornEngineFactory = Java.type("jdk.nashorn.api.scripting.NashornScriptEngineFactory");
d2d7e511c05c 8060688: Nashorn: Generated script class name fails --verify-code for names with special chars
sundar
parents:
diff changeset
    32
var ScriptEngine = Java.type("javax.script.ScriptEngine");
d2d7e511c05c 8060688: Nashorn: Generated script class name fails --verify-code for names with special chars
sundar
parents:
diff changeset
    33
var ScriptContext = Java.type("javax.script.ScriptContext");
d2d7e511c05c 8060688: Nashorn: Generated script class name fails --verify-code for names with special chars
sundar
parents:
diff changeset
    34
d2d7e511c05c 8060688: Nashorn: Generated script class name fails --verify-code for names with special chars
sundar
parents:
diff changeset
    35
var factory = new NashornEngineFactory();
d2d7e511c05c 8060688: Nashorn: Generated script class name fails --verify-code for names with special chars
sundar
parents:
diff changeset
    36
d2d7e511c05c 8060688: Nashorn: Generated script class name fails --verify-code for names with special chars
sundar
parents:
diff changeset
    37
var e = factory.getScriptEngine("--verify-code");
d2d7e511c05c 8060688: Nashorn: Generated script class name fails --verify-code for names with special chars
sundar
parents:
diff changeset
    38
d2d7e511c05c 8060688: Nashorn: Generated script class name fails --verify-code for names with special chars
sundar
parents:
diff changeset
    39
function evalAndCheck(code) {
d2d7e511c05c 8060688: Nashorn: Generated script class name fails --verify-code for names with special chars
sundar
parents:
diff changeset
    40
    try {
d2d7e511c05c 8060688: Nashorn: Generated script class name fails --verify-code for names with special chars
sundar
parents:
diff changeset
    41
        e.eval(code);
d2d7e511c05c 8060688: Nashorn: Generated script class name fails --verify-code for names with special chars
sundar
parents:
diff changeset
    42
    } catch (exp) {
d2d7e511c05c 8060688: Nashorn: Generated script class name fails --verify-code for names with special chars
sundar
parents:
diff changeset
    43
        exp.printStackTrace();
d2d7e511c05c 8060688: Nashorn: Generated script class name fails --verify-code for names with special chars
sundar
parents:
diff changeset
    44
    }
d2d7e511c05c 8060688: Nashorn: Generated script class name fails --verify-code for names with special chars
sundar
parents:
diff changeset
    45
}
d2d7e511c05c 8060688: Nashorn: Generated script class name fails --verify-code for names with special chars
sundar
parents:
diff changeset
    46
d2d7e511c05c 8060688: Nashorn: Generated script class name fails --verify-code for names with special chars
sundar
parents:
diff changeset
    47
// check default name
d2d7e511c05c 8060688: Nashorn: Generated script class name fails --verify-code for names with special chars
sundar
parents:
diff changeset
    48
evalAndCheck("var a = 3");
d2d7e511c05c 8060688: Nashorn: Generated script class name fails --verify-code for names with special chars
sundar
parents:
diff changeset
    49
// check few names with special chars
d2d7e511c05c 8060688: Nashorn: Generated script class name fails --verify-code for names with special chars
sundar
parents:
diff changeset
    50
var scontext = e.context;
d2d7e511c05c 8060688: Nashorn: Generated script class name fails --verify-code for names with special chars
sundar
parents:
diff changeset
    51
scontext.setAttribute(ScriptEngine.FILENAME, "<myscript>", ScriptContext.ENGINE_SCOPE);
d2d7e511c05c 8060688: Nashorn: Generated script class name fails --verify-code for names with special chars
sundar
parents:
diff changeset
    52
evalAndCheck("var h = 'hello'");
d2d7e511c05c 8060688: Nashorn: Generated script class name fails --verify-code for names with special chars
sundar
parents:
diff changeset
    53
scontext.setAttribute(ScriptEngine.FILENAME, "[myscript]", ScriptContext.ENGINE_SCOPE);
d2d7e511c05c 8060688: Nashorn: Generated script class name fails --verify-code for names with special chars
sundar
parents:
diff changeset
    54
evalAndCheck("var foo = 'world'");
d2d7e511c05c 8060688: Nashorn: Generated script class name fails --verify-code for names with special chars
sundar
parents:
diff changeset
    55
scontext.setAttribute(ScriptEngine.FILENAME, ";/\\$.", ScriptContext.ENGINE_SCOPE);
d2d7e511c05c 8060688: Nashorn: Generated script class name fails --verify-code for names with special chars
sundar
parents:
diff changeset
    56
evalAndCheck("var foo = 'helloworld'");