Skip to content

Commit 411e774

Browse files
authored
Merge pull request #21641 from pshipton/sendslots0.51
(0.51) Limit iterations of signature loop
2 parents d890900 + a9ea4e6 commit 411e774

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

runtime/util/sendslot.c

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222

2323
#include "j9.h"
2424
#include "util_internal.h"
25+
#include <stdint.h>
2526

2627
/* there is no error checking: the signature MUST be well-formed */
2728
UDATA
@@ -30,21 +31,25 @@ getSendSlotsFromSignature(const U_8* signature)
3031
UDATA sendArgs = 0;
3132
UDATA i = 1; /* 1 to skip the opening '(' */
3233

33-
for (; ; i++) {
34+
/* All UTF8 in the class file have a size represented by uint16_t. The size check
35+
* is only necessary for ASGCT where the signature provided may not be valid,
36+
* but is harmless in the normal runtime case.
37+
*/
38+
for (; i <= UINT16_MAX; i++) {
3439
switch (signature[i]) {
3540
case ')':
36-
return sendArgs;
41+
goto done;
3742
case '[':
3843
/* skip all '['s */
39-
for (i++; signature[i] == '['; i++);
44+
for (i++; (i <= UINT16_MAX) && (signature[i] == '['); i++);
4045
if (signature[i] == 'L') {
4146
/* FALL THRU */
4247
} else {
4348
sendArgs++;
4449
break;
4550
}
4651
case 'L':
47-
for (i++; signature[i] != ';'; i++);
52+
for (i++; (i <= UINT16_MAX) && (signature[i] != ';'); i++);
4853
sendArgs++;
4954
break;
5055
case 'D':
@@ -57,5 +62,7 @@ getSendSlotsFromSignature(const U_8* signature)
5762
break;
5863
}
5964
}
65+
done:
66+
return sendArgs;
6067
}
6168

0 commit comments

Comments
 (0)