Berry string literals containing NULL are truncated (#23312)

This commit is contained in:
s-hadinger 2025-04-17 22:12:35 +02:00 committed by GitHub
parent c2628c95f3
commit 082170374c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 6 additions and 1 deletions

View File

@ -13,6 +13,7 @@ All notable changes to this project will be documented in this file.
### Fixed
- Berry `bytes().asstring()` now truncates a string if buffer contains NULL
- Berry string literals containing NULL are truncated
### Removed

View File

@ -284,7 +284,8 @@ static void tr_string(blexer *lexer)
break;
}
}
lexer->buf.len = dst - lexbuf(lexer);
size_t len = dst - lexbuf(lexer);
lexer->buf.len = strnlen(lexbuf(lexer), len);
}
static int skip_newline(blexer *lexer)

View File

@ -84,3 +84,6 @@ var malformed_numbers = [
for i : malformed_numbers
test_source(i, 'malformed number')
end
#- ensure that string literal with NULL character is truncated -#
assert(size('aa\000bb\000cc') == 2)