Skip to content

Commit 4efcab8

Browse files
committed
Fix debug assert when creating a function with code that isn't a string (fix #2364)
1 parent 45c2b10 commit 4efcab8

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

ChangeLog

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
Fix memory leak (and assert in debug mode) when iterating over an object with proto with for...of (fix #2360)
3131
Fix debug assert when reversing an array with non-integer elements (fix #2362)
3232
Fix debug assert when using instanceof if __proto__ was set to non-object (fix #2363)
33+
Fix debug assert when creating a function with code that isn't a string (fix #2364)
3334

3435
2v17 : Bangle.js: When reading file info from a filename table, do it in blocks of 8 (20% faster file search)
3536
Bangle.js2: Increase flash buffer size from 16->32 bytes (5% performance increase)

src/jswrap_functions.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,11 @@ JsVar *jswrap_function_constructor(JsVar *args) {
114114
jsvObjectIteratorNext(&it);
115115
}
116116
jsvObjectIteratorFree(&it);
117+
if (!jsvIsString(v)) {
118+
jsExceptionHere(JSET_TYPEERROR,"Function code must be a String, got '%t'", v);
119+
jsvUnLock2(v,fn);
120+
return NULL;
121+
}
117122
jsvObjectSetChildAndUnLock(fn, JSPARSE_FUNCTION_CODE_NAME, v);
118123
return fn;
119124
}
@@ -298,7 +303,7 @@ JsVar *jswrap_btoa(JsVar *binaryData) {
298303
jsExceptionHere(JSET_ERROR, "Expecting a string or array, got %t", binaryData);
299304
return 0;
300305
}
301-
size_t inputLength = jsvGetLength(binaryData);
306+
size_t inputLength = (size_t)jsvGetLength(binaryData);
302307
size_t outputLength = ((inputLength+2)/3)*4;
303308
JsVar* base64Data = jsvNewStringOfLength((unsigned int)outputLength, NULL);
304309
if (!base64Data) return 0;
@@ -487,8 +492,8 @@ JsVar *jswrap_decodeURIComponent(JsVar *arg) {
487492
if (ch!='%') {
488493
jsvStringIteratorAppend(&dst, ch);
489494
} else {
490-
int hi = jsvStringIteratorGetCharAndNext(&it);
491-
int lo = jsvStringIteratorGetCharAndNext(&it);
495+
char hi = (char)jsvStringIteratorGetCharAndNext(&it);
496+
char lo = (char)jsvStringIteratorGetCharAndNext(&it);
492497
int v = (char)hexToByte(hi,lo);
493498
if (v<0) {
494499
jsExceptionHere(JSET_ERROR, "Invalid URI\n");

0 commit comments

Comments
 (0)