Skip to content

Commit b62ee29

Browse files
committed
Backport 992b6c464a9655438a808cf2e1979e04356123be
1 parent 552c686 commit b62ee29

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

hotspot/src/share/vm/runtime/arguments.cpp

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -595,18 +595,25 @@ char* SysClassPath::add_jars_to_path(char* path, const char* directory) {
595595
// Parses a memory size specification string.
596596
static bool atomull(const char *s, julong* result) {
597597
julong n = 0;
598-
int args_read = sscanf(s, JULONG_FORMAT, &n);
599-
if (args_read != 1) {
598+
599+
// First char must be a digit. Don't allow negative numbers or leading spaces.
600+
if (!isdigit(*s)) {
600601
return false;
601602
}
602-
while (*s != '\0' && isdigit(*s)) {
603-
s++;
603+
604+
char* remainder;
605+
errno = 0;
606+
n = strtoull(s, &remainder, 10);
607+
if (errno != 0) {
608+
return false;
604609
}
605-
// 4705540: illegal if more characters are found after the first non-digit
606-
if (strlen(s) > 1) {
610+
611+
// Fail if no number was read at all or if the remainder contains more than a single non-digit character.
612+
if (remainder == s || strlen(remainder) > 1) {
607613
return false;
608614
}
609-
switch (*s) {
615+
616+
switch (*remainder) {
610617
case 'T': case 't':
611618
*result = n * G * K;
612619
// Check for overflow.

0 commit comments

Comments
 (0)