Skip to content
Merged
Show file tree
Hide file tree
Changes from 7 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
20 changes: 14 additions & 6 deletions mettle/src/stdapi/fs/file.c
Original file line number Diff line number Diff line change
Expand Up @@ -560,16 +560,17 @@ fs_mkdir(struct tlv_handler_ctx *ctx)
return tlv_packet_response_result(ctx, TLV_RESULT_ENOMEM);
}

// take into account null byte at the end of path and the one we add in sprintf
base_dir = malloc(strlen(path_dup)+2);
// take into account null byte at the end of path and the one we add in snprintf
size_t base_max_len = strlen(path_dup) + 2;
base_dir = malloc(base_max_len);

if(base_dir == NULL)
{
free(path_dup);
return tlv_packet_response_result(ctx, TLV_RESULT_ENOMEM);
}

tmp = malloc(strlen(path_dup)+2);
tmp = malloc(base_max_len);

if(tmp == NULL)
{
Expand All @@ -579,15 +580,22 @@ fs_mkdir(struct tlv_handler_ctx *ctx)
}

dir = strtok(path_dup, "/");

if(dir == NULL) {
free(tmp);
free(path_dup);
free(base_dir);
return tlv_packet_response_result(ctx, TLV_RESULT_EINVAL);
}
Comment thread
dledda-r7 marked this conversation as resolved.

//address absolute paths — check original path since strtok modifies path_dup
if (path[0] == '/')
{
sprintf(base_dir, "/%s/", dir);
snprintf(base_dir, base_max_len, "/%s/", dir);
}
Comment thread
dledda-r7 marked this conversation as resolved.
else
{
sprintf(base_dir, "%s/", dir);
snprintf(base_dir, base_max_len, "%s/", dir);
}

while(dir != NULL)
Expand All @@ -614,7 +622,7 @@ fs_mkdir(struct tlv_handler_ctx *ctx)
dir = strtok(NULL, "/");
if(dir != NULL)
{
sprintf(tmp, "%s%s/", base_dir, dir);
snprintf(tmp, base_max_len, "%s%s/", base_dir, dir);
strcpy(base_dir, tmp);
}
}
Expand Down
14 changes: 13 additions & 1 deletion mettle/src/stdapi/ui/osx_desktop.m
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,19 @@
uint32_t quality = 0;
tlv_packet_get_u32(ctx->req, TLV_TYPE_DESKTOP_SCREENSHOT_QUALITY, &quality);
@autoreleasepool {
CGImageRef image = CGDisplayCreateImage(kCGDirectMainDisplay);
CGImageRef image;
#if __MAC_OS_X_VERSION_MAX_ALLOWED >= 140000
Comment thread
adfoster-r7 marked this conversation as resolved.
Outdated
if ( @available(macOS 14.4, *) )// errors on lower versions of macOS 14
{
// TODO add ScreenKit implementation
}
else
#endif // macOS 10.14+
{
#if __MAC_OS_X_VERSION_MAX_ALLOWED < 150000
image = CGDisplayCreateImage(kCGDirectMainDisplay);
#endif
}
CFMutableDataRef newImageData = CFDataCreateMutable(NULL, 0);
CGImageDestinationRef destination = CGImageDestinationCreateWithData(newImageData, kUTTypeJPEG, 1, NULL);
float compression = quality / 100;
Expand Down
Loading