Skip to content

Commit

Permalink
Add NULL check after call "s = JLI_WildcardExpandClasspath(s);"
Browse files Browse the repository at this point in the history
  • Loading branch information
sendaoYan committed Dec 16, 2024
1 parent 1ca177c commit 0d5395e
Showing 1 changed file with 2 additions and 9 deletions.
11 changes: 2 additions & 9 deletions src/java.base/share/native/libjli/java.c
Original file line number Diff line number Diff line change
Expand Up @@ -1018,23 +1018,16 @@ SetClassPath(const char *s)
if (s == NULL)
return;
s = JLI_WildcardExpandClasspath(s);
if (s == NULL)
return;
if (sizeof(format) - 2 + JLI_StrLen(s) < JLI_StrLen(s))
// s is became corrupted after expanding wildcards
return;
size_t defSize = sizeof(format)
- 2 /* strlen("%s") */
+ JLI_StrLen(s);
def = JLI_MemAlloc(defSize);
#if !defined(__clang_major__) && (__GNUC__ >= 7) && defined(__linux__)
_Pragma("GCC diagnostic push")
// Disable -Wstringop-overread which is introduced in GCC 7.
// https://gcc.gnu.org/gcc-7/changes.html
_Pragma("GCC diagnostic ignored \"-Wformat-truncation\"")
snprintf(def, defSize, format, s);
_Pragma("GCC diagnostic pop")
#else
snprintf(def, defSize, format, s);
#endif
AddOption(def, NULL);
if (s != orig)
JLI_MemFree((char *) s);
Expand Down

0 comments on commit 0d5395e

Please sign in to comment.