Skip to content

Commit fa14314

Browse files
committed
8303669: SelectVersion indexes past the end of the argv array
Reviewed-by: vromero
1 parent 25868b9 commit fa14314

File tree

3 files changed

+10
-4
lines changed

3 files changed

+10
-4
lines changed

src/java.base/share/native/libjli/java.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1007,7 +1007,7 @@ SelectVersion(int argc, char **argv, char **main_class)
10071007

10081008
argc--;
10091009
argv++;
1010-
while ((arg = *argv) != 0 && *arg == '-') {
1010+
while (argc > 0 && *(arg = *argv) == '-') {
10111011
has_arg = IsOptionWithArgument(argc, argv);
10121012
if (JLI_StrCCmp(arg, "-version:") == 0) {
10131013
JLI_ReportErrorMessage(SPC_ERROR1);
@@ -1209,7 +1209,7 @@ ParseArguments(int *pargc, char ***pargv,
12091209

12101210
*pret = 0;
12111211

1212-
while ((arg = *argv) != 0 && *arg == '-') {
1212+
while (argc > 0 && *(arg = *argv) == '-') {
12131213
char *option = NULL;
12141214
char *value = NULL;
12151215
int kind = GetOpt(&argc, &argv, &option, &value);

test/jdk/tools/launcher/JliLaunchTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424

2525
/**
2626
* @test
27-
* @bug 8213362 8238225
27+
* @bug 8213362 8238225 8303669
2828
* @comment Test JLI_Launch for tools distributed outside JDK
2929
* @library /test/lib
3030
* @run main/native JliLaunchTest

test/jdk/tools/launcher/exeJliLaunchTest.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,14 @@
3333
#include "java.h"
3434

3535
int
36-
main(int argc, char **argv)
36+
main(int argc, char **args)
3737
{
38+
//avoid null-terminated array of arguments to test JDK-8303669
39+
char *argv[argc];
40+
for (int i = 0; i < argc; i++) {
41+
argv[i] = args[i];
42+
}
43+
3844
return JLI_Launch(argc, argv,
3945
0, NULL,
4046
0, NULL,

0 commit comments

Comments
 (0)