RUSTSEC-2021-0123

Source
https://rustsec.org/advisories/RUSTSEC-2021-0123
Import Source
https://github.com/rustsec/advisory-db/blob/osv/crates/RUSTSEC-2021-0123.json
JSON Data
https://api.osv.dev/v1/vulns/RUSTSEC-2021-0123
Aliases
Published
2021-11-14T12:00:00Z
Modified
2023-11-08T04:07:11Z
Summary
Converting `NSString` to a String Truncates at Null Bytes
Details

Methods of NSString for conversion to a string may return a partial result. Since they call CStr::from_ptr on a pointer to the string buffer, the string is terminated at the first null byte, which might not be the end of the string.

In addition to the vulnerable functions listed for this issue, the implementations of Display, PartialEq, PartialOrd, and ToString for NSString are also affected, since they call those functions.

Impact

Since NSString is commonly used as the type for paths by the Foundation framework, null byte truncation might allow for easily bypassing file extension checks. For example, if a file name is provided by a user and validated to have one of a specific set of extensions, with validation taking place before truncation, an attacker can add an accepted extension after a null byte (e.g., file.exe\0.txt). After truncation, the file name used by the application would be file.exe.

It would be better to generate unique names for files, instead of using user-provided names, but not all applications take this approach.

Example:

let string = NSString::from_str("null\0byte");
println!("{}", string);

That example only prints the string "null".

Database specific
{
    "license": "CC0-1.0"
}
References

Affected packages

crates.io / fruity

Package

Affected ranges

Type
SEMVER
Events
Introduced
0.1.0
Fixed
0.3.0

Ecosystem specific

{
    "affected_functions": null,
    "affects": {
        "arch": [],
        "functions": [
            "fruity::foundation::NSString::to_str",
            "fruity::foundation::NSString::to_str_with_nul",
            "fruity::foundation::NSString::to_string",
            "fruity::foundation::NSString::to_string_with_nul"
        ],
        "os": []
    }
}

Database specific

categories
[]
cvss
null
informational
null
source
"https://github.com/rustsec/advisory-db/blob/osv/crates/RUSTSEC-2021-0123.json"