Fri, 08 Dec 2017 12:02:30 +0100
8193137: Nashorn crashes when given an empty script file
Reviewed-by: hannesw, sundar
Contributed-by: priya.lakshmi.muthuswamy@oracle.com
src/jdk/nashorn/tools/Shell.java | file | annotate | diff | comparison | revisions | |
test/script/nosecurity/JDK-8193137.js | file | annotate | diff | comparison | revisions |
1.1 --- a/src/jdk/nashorn/tools/Shell.java Mon Jun 29 21:30:31 2020 +0100 1.2 +++ b/src/jdk/nashorn/tools/Shell.java Fri Dec 08 12:02:30 2017 +0100 1.3 @@ -288,7 +288,7 @@ 1.4 } catch (IOException ioe) { 1.5 // ignore 1.6 } 1.7 - if (l.startsWith("#!")) { 1.8 + if (l != null && l.startsWith("#!")) { 1.9 shebangFilePos = i; 1.10 } 1.11 // We're only checking the first non-option argument. If it's not a shebang file, we're in normal
2.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 2.2 +++ b/test/script/nosecurity/JDK-8193137.js Fri Dec 08 12:02:30 2017 +0100 2.3 @@ -0,0 +1,62 @@ 2.4 +/* 2.5 + * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved. 2.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 2.7 + * 2.8 + * This code is free software; you can redistribute it and/or modify it 2.9 + * under the terms of the GNU General Public License version 2 only, as 2.10 + * published by the Free Software Foundation. Oracle designates this 2.11 + * particular file as subject to the "Classpath" exception as provided 2.12 + * by Oracle in the LICENSE file that accompanied this code. 2.13 + * 2.14 + * This code is distributed in the hope that it will be useful, but WITHOUT 2.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 2.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 2.17 + * version 2 for more details (a copy is included in the LICENSE file that 2.18 + * accompanied this code). 2.19 + * 2.20 + * You should have received a copy of the GNU General Public License version 2.21 + * 2 along with this work; if not, write to the Free Software Foundation, 2.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 2.23 + * 2.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 2.25 + * or visit www.oracle.com if you need additional information or have any 2.26 + * questions. 2.27 + */ 2.28 + 2.29 +/** 2.30 + * JDK-8193137 : Nashorn crashes when given an empty script file. 2.31 + * 2.32 + * @test 2.33 + * @option -scripting 2.34 + * @run 2.35 + */ 2.36 + 2.37 +if (typeof fail != 'function') { 2.38 + fail = print; 2.39 +} 2.40 + 2.41 +var System = java.lang.System; 2.42 +var File = java.io.File; 2.43 +var javahome = System.getProperty("java.home"); 2.44 +var nashornJar = new File(System.getProperty("nashorn.jar")); 2.45 +if (! nashornJar.isAbsolute()) { 2.46 + nashornJar = new File(".", nashornJar); 2.47 +} 2.48 + 2.49 +// we want to use nashorn.jar passed and not the one that comes with JRE 2.50 +var jjsCmd = javahome + "/../bin/jjs"; 2.51 +jjsCmd = jjsCmd.toString().replace(/\//g, File.separator); 2.52 +if (! new File(jjsCmd).isFile()) { 2.53 + jjsCmd = javahome + "/bin/jjs"; 2.54 + jjsCmd = jjsCmd.toString().replace(/\//g, File.separator); 2.55 +} 2.56 + 2.57 +$ENV.PWD=System.getProperty("user.dir") 2.58 + 2.59 +var emptyFile = new File($ENV.PWD+File.separator+"empty.js"); 2.60 +emptyFile.createNewFile(); 2.61 +emptyFile.deleteOnExit(); 2.62 + 2.63 +$EXEC(jjsCmd + " empty.js"); 2.64 +if($ERR != "") 2.65 + fail("jjs fails with empty script file");