diff --git a/mettle/src/stdapi/fs/file.c b/mettle/src/stdapi/fs/file.c index bfe45d66..dfbf3fd4 100644 --- a/mettle/src/stdapi/fs/file.c +++ b/mettle/src/stdapi/fs/file.c @@ -560,8 +560,9 @@ 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) { @@ -569,7 +570,7 @@ fs_mkdir(struct tlv_handler_ctx *ctx) return tlv_packet_response_result(ctx, TLV_RESULT_ENOMEM); } - tmp = malloc(strlen(path_dup)+2); + tmp = malloc(base_max_len); if(tmp == NULL) { @@ -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); + } //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); } else { - sprintf(base_dir, "%s/", dir); + snprintf(base_dir, base_max_len, "%s/", dir); } while(dir != NULL) @@ -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); } } diff --git a/mettle/src/stdapi/ui/osx_desktop.m b/mettle/src/stdapi/ui/osx_desktop.m index 094a19bb..5e4fe537 100644 --- a/mettle/src/stdapi/ui/osx_desktop.m +++ b/mettle/src/stdapi/ui/osx_desktop.m @@ -8,6 +8,15 @@ struct tlv_packet *p; uint32_t quality = 0; tlv_packet_get_u32(ctx->req, TLV_TYPE_DESKTOP_SCREENSHOT_QUALITY, &quality); + +#if __MAC_OS_X_VERSION_MAX_ALLOWED >= 140000 + if (@available(macOS 14.4, *)) { + // ScreenCaptureKit is required on macOS 14.4+ but is not yet implemented. + return tlv_packet_response_result(ctx, TLV_RESULT_FAILURE); + } +#endif + +#if __MAC_OS_X_VERSION_MAX_ALLOWED < 150000 @autoreleasepool { CGImageRef image = CGDisplayCreateImage(kCGDirectMainDisplay); CFMutableDataRef newImageData = CFDataCreateMutable(NULL, 0); @@ -26,4 +35,7 @@ } } return p; +#else + return tlv_packet_response_result(ctx, TLV_RESULT_FAILURE); +#endif }