8303669: SelectVersion indexes past the end of the argv array

Reviewed-by: vromero
This commit is contained in:
Adam Sotona 2023-05-19 08:09:37 +00:00
parent 25868b95ee
commit fa14314853
3 changed files with 10 additions and 4 deletions

View File

@ -1007,7 +1007,7 @@ SelectVersion(int argc, char **argv, char **main_class)
argc--;
argv++;
while ((arg = *argv) != 0 && *arg == '-') {
while (argc > 0 && *(arg = *argv) == '-') {
has_arg = IsOptionWithArgument(argc, argv);
if (JLI_StrCCmp(arg, "-version:") == 0) {
JLI_ReportErrorMessage(SPC_ERROR1);
@ -1209,7 +1209,7 @@ ParseArguments(int *pargc, char ***pargv,
*pret = 0;
while ((arg = *argv) != 0 && *arg == '-') {
while (argc > 0 && *(arg = *argv) == '-') {
char *option = NULL;
char *value = NULL;
int kind = GetOpt(&argc, &argv, &option, &value);

View File

@ -24,7 +24,7 @@
/**
* @test
* @bug 8213362 8238225
* @bug 8213362 8238225 8303669
* @comment Test JLI_Launch for tools distributed outside JDK
* @library /test/lib
* @run main/native JliLaunchTest

View File

@ -33,8 +33,14 @@
#include "java.h"
int
main(int argc, char **argv)
main(int argc, char **args)
{
//avoid null-terminated array of arguments to test JDK-8303669
char *argv[argc];
for (int i = 0; i < argc; i++) {
argv[i] = args[i];
}
return JLI_Launch(argc, argv,
0, NULL,
0, NULL,