提交 edc01f8e 编写于 作者: K ksrini

6390477: (launcher) replace unsafe usages of sprintf with snprintf

Reviewed-by: darcy, mchung
上级 fac29fe5
...@@ -712,19 +712,19 @@ SetModulesBootClassPath(const char *jrepath) ...@@ -712,19 +712,19 @@ SetModulesBootClassPath(const char *jrepath)
struct stat statbuf; struct stat statbuf;
/* return if jre/lib/rt.jar exists */ /* return if jre/lib/rt.jar exists */
sprintf(pathname, "%s%slib%srt.jar", jrepath, separator, separator); JLI_Snprintf(pathname, sizeof(pathname), "%s%slib%srt.jar", jrepath, separator, separator);
if (stat(pathname, &statbuf) == 0) { if (stat(pathname, &statbuf) == 0) {
return; return;
} }
/* return if jre/classes exists */ /* return if jre/classes exists */
sprintf(pathname, "%s%sclasses", jrepath, separator); JLI_Snprintf(pathname, sizeof(pathname), "%s%sclasses", jrepath, separator);
if (stat(pathname, &statbuf) == 0) { if (stat(pathname, &statbuf) == 0) {
return; return;
} }
/* modularized jre */ /* modularized jre */
sprintf(pathname, "%s%slib%s*", jrepath, separator, separator); JLI_Snprintf(pathname, sizeof(pathname), "%s%slib%s*", jrepath, separator, separator);
s = (char *) JLI_WildcardExpandClasspath(pathname); s = (char *) JLI_WildcardExpandClasspath(pathname);
def = JLI_MemAlloc(sizeof(format) def = JLI_MemAlloc(sizeof(format)
- 2 /* strlen("%s") */ - 2 /* strlen("%s") */
...@@ -1624,11 +1624,8 @@ ReadKnownVMs(const char *jrepath, const char * arch, jboolean speculative) ...@@ -1624,11 +1624,8 @@ ReadKnownVMs(const char *jrepath, const char * arch, jboolean speculative)
if (JLI_IsTraceLauncher()) { if (JLI_IsTraceLauncher()) {
start = CounterGet(); start = CounterGet();
} }
JLI_Snprintf(jvmCfgName, sizeof(jvmCfgName), "%s%slib%s%s%sjvm.cfg",
JLI_StrCpy(jvmCfgName, jrepath); jrepath, FILESEP, FILESEP, arch, FILESEP);
JLI_StrCat(jvmCfgName, FILESEP "lib" FILESEP);
JLI_StrCat(jvmCfgName, arch);
JLI_StrCat(jvmCfgName, FILESEP "jvm.cfg");
jvmCfg = fopen(jvmCfgName, "r"); jvmCfg = fopen(jvmCfgName, "r");
if (jvmCfg == NULL) { if (jvmCfg == NULL) {
......
...@@ -535,7 +535,7 @@ jboolean ...@@ -535,7 +535,7 @@ jboolean
GetApplicationHome(char *buf, jint bufsize) GetApplicationHome(char *buf, jint bufsize)
{ {
if (execname != NULL) { if (execname != NULL) {
JLI_StrNCpy(buf, execname, bufsize-1); JLI_Snprintf(buf, bufsize, "%s", execname);
buf[bufsize-1] = '\0'; buf[bufsize-1] = '\0';
} else { } else {
return JNI_FALSE; return JNI_FALSE;
......
...@@ -162,6 +162,10 @@ LoadMSVCRT() ...@@ -162,6 +162,10 @@ LoadMSVCRT()
#endif #endif
#ifdef CRT_DLL #ifdef CRT_DLL
if (GetJREPath(crtpath, MAXPATHLEN)) { if (GetJREPath(crtpath, MAXPATHLEN)) {
if (JLI_StrLen(crtpath) + JLI_StrLen("\\bin\\") + JLI_StrLen(CRT_DLL) >= MAXPATHLEN) {
JLI_ReportErrorMessage(JRE_ERROR11);
return JNI_FALSE;
}
(void)JLI_StrCat(crtpath, "\\bin\\" CRT_DLL); /* Add crt dll */ (void)JLI_StrCat(crtpath, "\\bin\\" CRT_DLL); /* Add crt dll */
JLI_TraceLauncher("CRT path is %s\n", crtpath); JLI_TraceLauncher("CRT path is %s\n", crtpath);
if (_access(crtpath, 0) == 0) { if (_access(crtpath, 0) == 0) {
...@@ -852,8 +856,7 @@ ExecJRE(char *jre, char **argv) { ...@@ -852,8 +856,7 @@ ExecJRE(char *jre, char **argv) {
/* /*
* If this isn't the selected version, exec the selected version. * If this isn't the selected version, exec the selected version.
*/ */
(void)JLI_StrCat(JLI_StrCat(JLI_StrCpy(path, jre), "\\bin\\"), progname); JLI_Snprintf(path, sizeof(path), "%s\\bin\\%s.exe", jre, progname);
(void)JLI_StrCat(path, ".exe");
/* /*
* Although Windows has an execv() entrypoint, it doesn't actually * Although Windows has an execv() entrypoint, it doesn't actually
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册