src/solaris/bin/jexec.c
Print this page
*** 1,7 ****
/*
! * Copyright (c) 1999, 2012, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
--- 1,7 ----
/*
! * Copyright (c) 1999, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
*** 88,97 ****
--- 88,98 ----
static const int BAD_MAGIC = ENOEXEC;
static const char * BAD_EXEC_MSG = "jexec failed";
static const char * CRAZY_EXEC_MSG = "missing args";
static const char * MISSING_JAVA_MSG = "can't locate java";
+ static const char * BAD_ARG_MSG = "incorrect number of arguments";
#ifdef __linux__
static const char * BAD_PATHNAME_MSG = "invalid path";
static const char * BAD_FILE_MSG = "invalid file";
static const char * BAD_MAGIC_MSG = "invalid file (bad magic number)";
#endif
*** 154,163 ****
--- 155,165 ----
* args array. */
char java[PATH_MAX + 1]; /* path to java binary */
const char ** nargv = NULL; /* new args array */
int nargc = 0; /* new args array count */
int argi = 0; /* index into old array */
+ size_t alen = 0; /* length of new array */
/* Make sure we have something to work with */
if ((argc < 1) || (argv == NULL)) {
/* Shouldn't happen... */
errorExit(CRAZY_EXEC, CRAZY_EXEC_MSG);
*** 166,177 ****
/* Get the path to the java binary, which is in a known position relative
* to our current position, which is in argv[0]. */
if (getJavaPath(argv[argi++], java, RELATIVE_DEPTH) != 0) {
errorExit(errno, MISSING_JAVA_MSG);
}
!
! nargv = (const char **) malloc((argc + 2) * (sizeof (const char *)));
nargv[nargc++] = java;
#ifdef __linux__
/* The "-jar" flag is already in the original args list on Solaris,
* so it only needs to be added on Linux. */
--- 168,182 ----
/* Get the path to the java binary, which is in a known position relative
* to our current position, which is in argv[0]. */
if (getJavaPath(argv[argi++], java, RELATIVE_DEPTH) != 0) {
errorExit(errno, MISSING_JAVA_MSG);
}
! alen = (argc + 2) * (sizeof (const char *));
! if (alen <= 0 || alen > INT_MAX / sizeof(char *)) {
! errorExit(3, BAD_ARG_MSG);
! }
! nargv = (const char **) malloc(alen);
nargv[nargc++] = java;
#ifdef __linux__
/* The "-jar" flag is already in the original args list on Solaris,
* so it only needs to be added on Linux. */