From 7e5301571a565f92e853338deb74dd310b5e5c4c Mon Sep 17 00:00:00 2001 From: jbx81-1337 Date: Wed, 17 Jun 2026 17:27:24 +0200 Subject: [PATCH 1/8] fix: fix mettle macos deprecated functions --- mettle/src/stdapi/fs/file.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/mettle/src/stdapi/fs/file.c b/mettle/src/stdapi/fs/file.c index bfe45d66..808fc287 100644 --- a/mettle/src/stdapi/fs/file.c +++ b/mettle/src/stdapi/fs/file.c @@ -561,7 +561,8 @@ fs_mkdir(struct tlv_handler_ctx *ctx) } // take into account null byte at the end of path and the one we add in sprintf - base_dir = malloc(strlen(path_dup)+2); + unsigned int 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) { @@ -583,11 +584,11 @@ fs_mkdir(struct tlv_handler_ctx *ctx) //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 +615,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); } } From 22312f9341d20e5b5b53036efc7eb069fb182c43 Mon Sep 17 00:00:00 2001 From: jbx81 <47637476+jbx81-1337@users.noreply.github.com> Date: Wed, 17 Jun 2026 17:41:39 +0200 Subject: [PATCH 2/8] fix: fix base_max_len datatype to be size_t --- mettle/src/stdapi/fs/file.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mettle/src/stdapi/fs/file.c b/mettle/src/stdapi/fs/file.c index 808fc287..4c3079c5 100644 --- a/mettle/src/stdapi/fs/file.c +++ b/mettle/src/stdapi/fs/file.c @@ -561,7 +561,7 @@ fs_mkdir(struct tlv_handler_ctx *ctx) } // take into account null byte at the end of path and the one we add in sprintf - unsigned int base_max_len = strlen(path_dup)+2; + size_t base_max_len = strlen(path_dup) + 2; base_dir = malloc(base_max_len); if(base_dir == NULL) From 43e54e88b8acd554a677120ed5c0ee80bd70f63c Mon Sep 17 00:00:00 2001 From: jbx81-1337 Date: Wed, 17 Jun 2026 17:49:32 +0200 Subject: [PATCH 3/8] fix: handle potential NULL of strtok on fs_mkdir --- mettle/src/stdapi/fs/file.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/mettle/src/stdapi/fs/file.c b/mettle/src/stdapi/fs/file.c index 4c3079c5..ad727786 100644 --- a/mettle/src/stdapi/fs/file.c +++ b/mettle/src/stdapi/fs/file.c @@ -580,6 +580,12 @@ fs_mkdir(struct tlv_handler_ctx *ctx) } dir = strtok(path_dup, "/"); + + if(dir == NULL) { + 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] == '/') From 0c307b4d863adbb2c3f85dfdc3f8ab01eabfdcf2 Mon Sep 17 00:00:00 2001 From: Diego Ledda Date: Wed, 17 Jun 2026 17:52:35 +0200 Subject: [PATCH 4/8] fix: freeing tmp buffer if strtok returns NULL --- mettle/src/stdapi/fs/file.c | 1 + 1 file changed, 1 insertion(+) diff --git a/mettle/src/stdapi/fs/file.c b/mettle/src/stdapi/fs/file.c index ad727786..ca8fda00 100644 --- a/mettle/src/stdapi/fs/file.c +++ b/mettle/src/stdapi/fs/file.c @@ -582,6 +582,7 @@ 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); From 1fa8458354d82c5f4d2fddc3d5ba807e4bae5e93 Mon Sep 17 00:00:00 2001 From: Diego Ledda Date: Wed, 17 Jun 2026 17:55:55 +0200 Subject: [PATCH 5/8] chore: update used function name in comment --- mettle/src/stdapi/fs/file.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mettle/src/stdapi/fs/file.c b/mettle/src/stdapi/fs/file.c index ca8fda00..dfbf3fd4 100644 --- a/mettle/src/stdapi/fs/file.c +++ b/mettle/src/stdapi/fs/file.c @@ -560,7 +560,7 @@ 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 + // 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); From bb0dd8150e2e71537b20a7fb33e493c52705e3fe Mon Sep 17 00:00:00 2001 From: jbx81-1337 Date: Mon, 29 Jun 2026 17:58:19 +0200 Subject: [PATCH 6/8] fix: fixing failing mettle macos ci --- mettle/src/stdapi/ui/osx_desktop.m | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/mettle/src/stdapi/ui/osx_desktop.m b/mettle/src/stdapi/ui/osx_desktop.m index 094a19bb..d68344d2 100644 --- a/mettle/src/stdapi/ui/osx_desktop.m +++ b/mettle/src/stdapi/ui/osx_desktop.m @@ -9,7 +9,18 @@ uint32_t quality = 0; tlv_packet_get_u32(ctx->req, TLV_TYPE_DESKTOP_SCREENSHOT_QUALITY, &quality); @autoreleasepool { - CGImageRef image = CGDisplayCreateImage(kCGDirectMainDisplay); + #if __MAC_OS_X_VERSION_MAX_ALLOWED >= 140000 + if ( WX_IS_MACOS_AVAILABLE(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 + CGImageRef image = CGDisplayCreateImage(kCGDirectMainDisplay); +#endif + } CFMutableDataRef newImageData = CFDataCreateMutable(NULL, 0); CGImageDestinationRef destination = CGImageDestinationCreateWithData(newImageData, kUTTypeJPEG, 1, NULL); float compression = quality / 100; From 21e8960fdaf3c617668afc46239d50f111884c08 Mon Sep 17 00:00:00 2001 From: jbx81-1337 Date: Mon, 29 Jun 2026 18:27:56 +0200 Subject: [PATCH 7/8] fix: fixing declaration issue on osx_desktop --- mettle/src/stdapi/ui/osx_desktop.m | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/mettle/src/stdapi/ui/osx_desktop.m b/mettle/src/stdapi/ui/osx_desktop.m index d68344d2..dd90842f 100644 --- a/mettle/src/stdapi/ui/osx_desktop.m +++ b/mettle/src/stdapi/ui/osx_desktop.m @@ -9,17 +9,18 @@ uint32_t quality = 0; tlv_packet_get_u32(ctx->req, TLV_TYPE_DESKTOP_SCREENSHOT_QUALITY, &quality); @autoreleasepool { + CGImageRef image; #if __MAC_OS_X_VERSION_MAX_ALLOWED >= 140000 - if ( WX_IS_MACOS_AVAILABLE(14, 4) ) // errors on lower versions of macOS 14 + if ( @available(macOS 14.4, *) )// errors on lower versions of macOS 14 { // TODO add ScreenKit implementation } else -#endif // macOS 10.14+ + #endif // macOS 10.14+ { -#if __MAC_OS_X_VERSION_MAX_ALLOWED < 150000 - CGImageRef image = CGDisplayCreateImage(kCGDirectMainDisplay); -#endif + #if __MAC_OS_X_VERSION_MAX_ALLOWED < 150000 + image = CGDisplayCreateImage(kCGDirectMainDisplay); + #endif } CFMutableDataRef newImageData = CFDataCreateMutable(NULL, 0); CGImageDestinationRef destination = CGImageDestinationCreateWithData(newImageData, kUTTypeJPEG, 1, NULL); From 9c13f727f3981a2df430de3673d52cff734c8b00 Mon Sep 17 00:00:00 2001 From: adfoster-r7 Date: Thu, 2 Jul 2026 15:23:57 +0100 Subject: [PATCH 8/8] Update OSX Desktop logic --- mettle/src/stdapi/ui/osx_desktop.m | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/mettle/src/stdapi/ui/osx_desktop.m b/mettle/src/stdapi/ui/osx_desktop.m index dd90842f..5e4fe537 100644 --- a/mettle/src/stdapi/ui/osx_desktop.m +++ b/mettle/src/stdapi/ui/osx_desktop.m @@ -8,20 +8,17 @@ 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; - #if __MAC_OS_X_VERSION_MAX_ALLOWED >= 140000 - 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 - } + CGImageRef image = CGDisplayCreateImage(kCGDirectMainDisplay); CFMutableDataRef newImageData = CFDataCreateMutable(NULL, 0); CGImageDestinationRef destination = CGImageDestinationCreateWithData(newImageData, kUTTypeJPEG, 1, NULL); float compression = quality / 100; @@ -38,4 +35,7 @@ } } return p; +#else + return tlv_packet_response_result(ctx, TLV_RESULT_FAILURE); +#endif }