Skip to content

Commit bff9f5e

Browse files
committed
src: harden SlicedString::ToString
Add some extra checks to make sure we won't crash when stringifying a (possibly corrupted) SlicedString. PR-URL: #332 Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
1 parent e8896e0 commit bff9f5e

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

src/llv8-inl.h

+3-1
Original file line numberDiff line numberDiff line change
@@ -826,6 +826,7 @@ inline std::string ConsString::ToString(Error& err) {
826826
inline std::string SlicedString::ToString(Error& err) {
827827
String parent = Parent(err);
828828
if (err.Fail()) return std::string();
829+
RETURN_IF_INVALID(parent, std::string());
829830

830831
// TODO - Remove when we add support for external strings
831832
// We can't use the offset and length safely if we get "(external)"
@@ -838,6 +839,7 @@ inline std::string SlicedString::ToString(Error& err) {
838839

839840
Smi offset = Offset(err);
840841
if (err.Fail()) return std::string();
842+
RETURN_IF_INVALID(offset, std::string());
841843

842844
CheckedType<int32_t> length = Length(err);
843845
RETURN_IF_INVALID(length, std::string());
@@ -847,7 +849,7 @@ inline std::string SlicedString::ToString(Error& err) {
847849

848850
int64_t off = offset.GetValue();
849851
int64_t tmp_size = tmp.size();
850-
if (off > tmp_size || *length > tmp_size) {
852+
if (off > tmp_size || *length > tmp_size || *length < 0 || off < 0) {
851853
err = Error::Failure("Failed to display sliced string 0x%016" PRIx64
852854
" (offset = 0x%016" PRIx64
853855
", length = %d) from parent string 0x%016" PRIx64

0 commit comments

Comments
 (0)