hotspot/test/runtime/CommandLine/TestLongUnrecognizedVMOption.java
author ddmitriev
Thu, 02 Jul 2015 12:25:55 +0300
changeset 31624 a184abca1684
child 38152 80e5da81fb2c
permissions -rw-r--r--
8129786: Buffer overrun when passing long not existing option in JDK 9 Summary: Only make the obsolete check for valid arguments(length less than 256) Reviewed-by: dcubed, dholmes
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
31624
a184abca1684 8129786: Buffer overrun when passing long not existing option in JDK 9
ddmitriev
parents:
diff changeset
     1
/*
a184abca1684 8129786: Buffer overrun when passing long not existing option in JDK 9
ddmitriev
parents:
diff changeset
     2
 * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
a184abca1684 8129786: Buffer overrun when passing long not existing option in JDK 9
ddmitriev
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
a184abca1684 8129786: Buffer overrun when passing long not existing option in JDK 9
ddmitriev
parents:
diff changeset
     4
 *
a184abca1684 8129786: Buffer overrun when passing long not existing option in JDK 9
ddmitriev
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
a184abca1684 8129786: Buffer overrun when passing long not existing option in JDK 9
ddmitriev
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
a184abca1684 8129786: Buffer overrun when passing long not existing option in JDK 9
ddmitriev
parents:
diff changeset
     7
 * published by the Free Software Foundation.
a184abca1684 8129786: Buffer overrun when passing long not existing option in JDK 9
ddmitriev
parents:
diff changeset
     8
 *
a184abca1684 8129786: Buffer overrun when passing long not existing option in JDK 9
ddmitriev
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
a184abca1684 8129786: Buffer overrun when passing long not existing option in JDK 9
ddmitriev
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
a184abca1684 8129786: Buffer overrun when passing long not existing option in JDK 9
ddmitriev
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
a184abca1684 8129786: Buffer overrun when passing long not existing option in JDK 9
ddmitriev
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
a184abca1684 8129786: Buffer overrun when passing long not existing option in JDK 9
ddmitriev
parents:
diff changeset
    13
 * accompanied this code).
a184abca1684 8129786: Buffer overrun when passing long not existing option in JDK 9
ddmitriev
parents:
diff changeset
    14
 *
a184abca1684 8129786: Buffer overrun when passing long not existing option in JDK 9
ddmitriev
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
a184abca1684 8129786: Buffer overrun when passing long not existing option in JDK 9
ddmitriev
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
a184abca1684 8129786: Buffer overrun when passing long not existing option in JDK 9
ddmitriev
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
a184abca1684 8129786: Buffer overrun when passing long not existing option in JDK 9
ddmitriev
parents:
diff changeset
    18
 *
a184abca1684 8129786: Buffer overrun when passing long not existing option in JDK 9
ddmitriev
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
a184abca1684 8129786: Buffer overrun when passing long not existing option in JDK 9
ddmitriev
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
a184abca1684 8129786: Buffer overrun when passing long not existing option in JDK 9
ddmitriev
parents:
diff changeset
    21
 * questions.
a184abca1684 8129786: Buffer overrun when passing long not existing option in JDK 9
ddmitriev
parents:
diff changeset
    22
 */
a184abca1684 8129786: Buffer overrun when passing long not existing option in JDK 9
ddmitriev
parents:
diff changeset
    23
a184abca1684 8129786: Buffer overrun when passing long not existing option in JDK 9
ddmitriev
parents:
diff changeset
    24
/*
a184abca1684 8129786: Buffer overrun when passing long not existing option in JDK 9
ddmitriev
parents:
diff changeset
    25
 * @test
a184abca1684 8129786: Buffer overrun when passing long not existing option in JDK 9
ddmitriev
parents:
diff changeset
    26
 * @bug 8129786
a184abca1684 8129786: Buffer overrun when passing long not existing option in JDK 9
ddmitriev
parents:
diff changeset
    27
 * @summary Verify that JVM correctly processes very long unrecognized VM option
a184abca1684 8129786: Buffer overrun when passing long not existing option in JDK 9
ddmitriev
parents:
diff changeset
    28
 * @library /testlibrary
a184abca1684 8129786: Buffer overrun when passing long not existing option in JDK 9
ddmitriev
parents:
diff changeset
    29
 * @modules java.management
a184abca1684 8129786: Buffer overrun when passing long not existing option in JDK 9
ddmitriev
parents:
diff changeset
    30
 * @run main TestLongUnrecognizedVMOption
a184abca1684 8129786: Buffer overrun when passing long not existing option in JDK 9
ddmitriev
parents:
diff changeset
    31
 */
a184abca1684 8129786: Buffer overrun when passing long not existing option in JDK 9
ddmitriev
parents:
diff changeset
    32
a184abca1684 8129786: Buffer overrun when passing long not existing option in JDK 9
ddmitriev
parents:
diff changeset
    33
import jdk.test.lib.OutputAnalyzer;
a184abca1684 8129786: Buffer overrun when passing long not existing option in JDK 9
ddmitriev
parents:
diff changeset
    34
import jdk.test.lib.ProcessTools;
a184abca1684 8129786: Buffer overrun when passing long not existing option in JDK 9
ddmitriev
parents:
diff changeset
    35
a184abca1684 8129786: Buffer overrun when passing long not existing option in JDK 9
ddmitriev
parents:
diff changeset
    36
public class TestLongUnrecognizedVMOption {
a184abca1684 8129786: Buffer overrun when passing long not existing option in JDK 9
ddmitriev
parents:
diff changeset
    37
a184abca1684 8129786: Buffer overrun when passing long not existing option in JDK 9
ddmitriev
parents:
diff changeset
    38
    /* Create option with very long length(greater than 500 characters) */
a184abca1684 8129786: Buffer overrun when passing long not existing option in JDK 9
ddmitriev
parents:
diff changeset
    39
    private static final String VERY_LONG_OPTION = String.format("%500s=10", "unrecognizedoption").replace(" ", "a");
a184abca1684 8129786: Buffer overrun when passing long not existing option in JDK 9
ddmitriev
parents:
diff changeset
    40
a184abca1684 8129786: Buffer overrun when passing long not existing option in JDK 9
ddmitriev
parents:
diff changeset
    41
    public static void main(String[] args) throws Exception {
a184abca1684 8129786: Buffer overrun when passing long not existing option in JDK 9
ddmitriev
parents:
diff changeset
    42
        OutputAnalyzer output;
a184abca1684 8129786: Buffer overrun when passing long not existing option in JDK 9
ddmitriev
parents:
diff changeset
    43
a184abca1684 8129786: Buffer overrun when passing long not existing option in JDK 9
ddmitriev
parents:
diff changeset
    44
        output = new OutputAnalyzer(ProcessTools.createJavaProcessBuilder("-XX:" + VERY_LONG_OPTION, "-version").start());
a184abca1684 8129786: Buffer overrun when passing long not existing option in JDK 9
ddmitriev
parents:
diff changeset
    45
        output.shouldHaveExitValue(1);
a184abca1684 8129786: Buffer overrun when passing long not existing option in JDK 9
ddmitriev
parents:
diff changeset
    46
        output.shouldContain(String.format("Unrecognized VM option '%s'", VERY_LONG_OPTION));
a184abca1684 8129786: Buffer overrun when passing long not existing option in JDK 9
ddmitriev
parents:
diff changeset
    47
    }
a184abca1684 8129786: Buffer overrun when passing long not existing option in JDK 9
ddmitriev
parents:
diff changeset
    48
}