Skip to content

Commit bfa94b7

Browse files
committed
resolve use of VLA in JWT encoder function
1 parent 9c680e8 commit bfa94b7

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

src/ArduinoJsonJWT.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,17 +102,21 @@ String ArduinoJsonJWT::encode(const char *cstr, int inputLen) {
102102
base64_init_encodestate(&_state);
103103
size_t encodedLength = base64_encode_expected_len(inputLen) + 1;
104104
#endif
105-
106-
// prepare buffer of correct length
107-
char buffer[encodedLength];
105+
// prepare buffer of correct length, returning an empty string on failure
106+
char* buffer = (char*) malloc(encodedLength * sizeof(char));
107+
if (buffer == nullptr) {
108+
return "";
109+
}
108110

109111
// encode to buffer
110112
int len = base64_encode_block(cstr, inputLen, &buffer[0], &_state);
111113
len += base64_encode_blockend(&buffer[len], &_state);
112114
buffer[len] = 0;
113115

114-
// convert to arduino string
116+
// convert to arduino string, freeing buffer
115117
String value = String(buffer);
118+
free(buffer);
119+
buffer=nullptr;
116120

117121
// remove padding and convert to URL safe form
118122
while (value.length() > 0 && value.charAt(value.length() - 1) == '='){

0 commit comments

Comments
 (0)