Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix passing non null terminated strings for null terminated params #1924

Merged
merged 2 commits into from
May 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions core/media/AvfMediaEngine.mm
Original file line number Diff line number Diff line change
Expand Up @@ -194,14 +194,14 @@ - (void)observeValueForKeyPath:(NSString*)keyPath
// Media Framework doesn't percent encode the URL, so the path portion is just a native file path.
// Extract it and then use it create a proper URL.
Path = sourceUri.substr(7);
NSString* nsPath = [NSString stringWithUTF8String:Path.data()];
NSString* nsPath = [[NSString alloc] initWithBytes:Path.data() length:Path.size() encoding:NSUTF8StringEncoding];
nsMediaUrl = [NSURL fileURLWithPath:nsPath isDirectory:NO];
}
else
{
// Assume that this has been percent encoded for now - when we support HTTP Live Streaming we will need to check
// for that.
NSString* nsUri = [NSString stringWithUTF8String:sourceUri.data()];
NSString* nsUri = [[NSString alloc] initWithBytes:sourceUri.data() length:sourceUri.size() encoding:NSUTF8StringEncoding];
nsMediaUrl = [NSURL URLWithString:nsUri];
}

Expand Down
12 changes: 6 additions & 6 deletions core/platform/apple/FileUtils-apple.mm
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ of this software and associated documentation files (the "Software"), to deal
{
// Search path is an absolute path.
BOOL isDir = NO;
if ([s_fileManager fileExistsAtPath:[NSString stringWithUTF8String:filePath.data()] isDirectory:&isDir] && !isDir)
if ([s_fileManager fileExistsAtPath:[[NSString alloc] initWithBytes:filePath.data() length:filePath.size() encoding:NSUTF8StringEncoding] isDirectory:&isDir] && !isDir)
{
ret = true;
}
Expand Down Expand Up @@ -207,7 +207,7 @@ static int unlink_cb(const char* fpath, const struct stat* sb, int typeflag, str
if (path[0] == '/')
{
BOOL isDir = NO;
if ([s_fileManager fileExistsAtPath:[NSString stringWithUTF8String:path.data()] isDirectory:&isDir])
if ([s_fileManager fileExistsAtPath:[[NSString alloc] initWithBytes:path.data() length:path.size() encoding:NSUTF8StringEncoding] isDirectory:&isDir])
{
return appendTrailingSlashToDir(isDir ? path : "");
}
Expand All @@ -232,9 +232,9 @@ static int unlink_cb(const char* fpath, const struct stat* sb, int typeflag, str
// Build full path for the file
if (directory[0] != '/')
{
NSString* path = [pimpl_->getBundle() pathForResource:[NSString stringWithUTF8String:filename.data()]
NSString* path = [pimpl_->getBundle() pathForResource:[[NSString alloc] initWithBytes:filename.data() length:filename.size() encoding:NSUTF8StringEncoding]
ofType:nil
inDirectory:[NSString stringWithUTF8String:directory.data()]];
inDirectory:[[NSString alloc] initWithBytes:directory.data() length:directory.size() encoding:NSUTF8StringEncoding]];
if (path != nil)
{
fullPath = [path UTF8String];
Expand Down Expand Up @@ -265,14 +265,14 @@ static int unlink_cb(const char* fpath, const struct stat* sb, int typeflag, str

NSError* error;

bool result = [s_fileManager createDirectoryAtPath:[NSString stringWithUTF8String:path.data()]
bool result = [s_fileManager createDirectoryAtPath:[[NSString alloc] initWithBytes:path.data() length:path.size() encoding:NSUTF8StringEncoding]
withIntermediateDirectories:YES
attributes:nil
error:&error];

if (!result && error != nil)
{
AXLOGERROR("Fail to create directory \"%s\": %s", path.data(), [error.localizedDescription UTF8String]);
AXLOGERROR("Fail to create directory \"%s\": %s", std::string(path).c_str(), [error.localizedDescription UTF8String]);
}

return result;
Expand Down
2 changes: 1 addition & 1 deletion core/platform/ios/Device-ios.mm
Original file line number Diff line number Diff line change
Expand Up @@ -463,7 +463,7 @@ static bool _initWithString(std::string_view text,

AX_BREAK_IF(!font);

NSString* str = [NSString stringWithUTF8String:text.data()];
NSString* str = [[NSString alloc] initWithBytes:text.data() length:text.size() encoding:NSUTF8StringEncoding];
AX_BREAK_IF(!str);

CGSize dimensions;
Expand Down
2 changes: 1 addition & 1 deletion core/platform/mac/Device-mac.mm
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ static bool _initWithString(std::string_view text,

do
{
NSString* string = [NSString stringWithUTF8String:text.data()];
NSString* string = [[NSString alloc] initWithBytes:text.data() length:text.size() encoding:NSUTF8StringEncoding];
AX_BREAK_IF(!string);

id font = _createSystemFont(fontName, size);
Expand Down