Skip to content

Commit

Permalink
Fix NewExternalString length (#99)
Browse files Browse the repository at this point in the history
  • Loading branch information
CarlesDD authored Mar 22, 2024
1 parent 7a9e608 commit 7643f11
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/tainted/string_resource.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ void StringResource::CopyCharArrToUint16Arr(const char* charArr, uint16_t* resul
v8::Local<v8::String> NewExternalString(v8::Isolate* isolate, v8::Local<v8::Value> obj) {
v8::String::Utf8Value originalStringValue(isolate, obj);
const char* originalCharArr = *originalStringValue;
auto resource = new StringResource(originalCharArr, originalStringValue.length());
int length = v8::Local<v8::String>::Cast(obj)->Length();
auto resource = new StringResource(originalCharArr, length);
return v8::String::NewExternalTwoByte(isolate, resource).ToLocalChecked();
}
} // namespace tainted
Expand Down
12 changes: 12 additions & 0 deletions test/js/new_tainted_string.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -167,4 +167,16 @@ describe('Taint strings', function () {
assert.strictEqual(true, TaintedUtils.isTainted(id, taintedOneChar), 'Must be tainted')
assert.strictEqual(false, TaintedUtils.isTainted(id, oneChar), 'Can not be tainted')
})

describe('Taint special one char strings', function () {
const specialOneCharStrings = ['佫', 'ü', 'ô', 'é', 'à']

specialOneCharStrings.forEach((testStr) => {
it(`Taint ${testStr}`, function () {
const taintedStr = TaintedUtils.newTaintedString(id, testStr, 'param', 'request')
assert.strictEqual(true, TaintedUtils.isTainted(id, taintedStr), 'Must be tainted')
assert.strictEqual(testStr, taintedStr, 'Strings must be equal')
})
})
})
})

0 comments on commit 7643f11

Please sign in to comment.