Skip to content

Commit

Permalink
Check for nul values in cstr macros. Fixes #28
Browse files Browse the repository at this point in the history
  • Loading branch information
starkat99 committed Jul 15, 2022
1 parent 0f2e403 commit 614a399
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

## [Unreleased]
### Fixed
- Correctly check for and error on nul values in C-string macros `u16cstr!`, `u32cstr!`, and
`widecstr!`. Fixes [#28].

## [1.0.1] - 2022-06-24 <a name="1.0.1"></a>
### Fixed
Expand Down Expand Up @@ -322,6 +325,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
[#19]: https://github.com/starkat99/widestring-rs/issues/19
[#20]: https://github.com/starkat99/widestring-rs/issues/20
[#22]: https://github.com/starkat99/widestring-rs/issues/22
[#28]: https://github.com/starkat99/widestring-rs/issues/28

[@nicbn]: https://github.com/nicbn
[@joshwd36]: https://github.com/joshwb36
Expand Down
6 changes: 6 additions & 0 deletions src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ macro_rules! implement_utf16_macro {
let mut _widestring_i = 0;
while let $crate::internals::core::option::Option::Some((_widestring_ch, _widestring_rest)) = $crate::internals::next_code_point(_widestring_bytes) {
_widestring_bytes = _widestring_rest;
if $extra_len > 0 && _widestring_ch == 0 {
panic!("invalid NUL value found in string literal");
}
// https://doc.rust-lang.org/std/primitive.char.html#method.encode_utf16
if _widestring_ch & 0xFFFF == _widestring_ch {
_widestring_buffer[_widestring_i] = _widestring_ch as $crate::internals::core::primitive::u16;
Expand Down Expand Up @@ -104,6 +107,9 @@ macro_rules! implement_utf32_macro {
let mut _widestring_bytes = _WIDESTRING_U32_MACRO_UTF8.as_bytes();
let mut _widestring_i = 0;
while let $crate::internals::core::option::Option::Some((_widestring_ch, _widestring_rest)) = $crate::internals::next_code_point(_widestring_bytes) {
if $extra_len > 0 && _widestring_ch == 0 {
panic!("invalid NUL value found in string literal");
}
_widestring_bytes = _widestring_rest;
_widestring_buffer[_widestring_i] = _widestring_ch;
_widestring_i += 1;
Expand Down

0 comments on commit 614a399

Please sign in to comment.