6733959: Insufficient checks for "Main-Class" manifest entry in JAR files
Summary: Fixes a buffer overrun problem with a very long Main-Class attribute.
Reviewed-by: darcy
diff --git a/src/share/bin/java.c b/src/share/bin/java.c
index f7cbcdc..b351fe3 100644
--- a/src/share/bin/java.c
+++ b/src/share/bin/java.c
@@ -987,8 +987,14 @@
* to avoid locating, expanding and parsing the manifest extra
* times.
*/
- if (info.main_class != NULL)
- (void)JLI_StrCat(env_entry, info.main_class);
+ if (info.main_class != NULL) {
+ if (JLI_StrLen(info.main_class) <= MAXNAMELEN) {
+ (void)JLI_StrCat(env_entry, info.main_class);
+ } else {
+ ReportErrorMessage(CLS_ERROR5, MAXNAMELEN);
+ exit(1);
+ }
+ }
(void)putenv(env_entry);
ExecJRE(jre, new_argv);
JLI_FreeManifest();