From 74b0dc7d950c98ed38015a5f8f85e199637f7948 Mon Sep 17 00:00:00 2001 From: Matthias Melcher Date: Sun, 11 May 2025 12:30:12 +0200 Subject: Fix address sanitizer exception for macOS native file chooser The `memcmp` call would crash in Adress sanitizer if the memory compare would run into an undefined buffer. `memcmp` is not guaranteed to stop reading a buffer if a difference is found. --- src/Fl_Native_File_Chooser_MAC.mm | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'src/Fl_Native_File_Chooser_MAC.mm') diff --git a/src/Fl_Native_File_Chooser_MAC.mm b/src/Fl_Native_File_Chooser_MAC.mm index 77cf16585..8bb74e0fa 100644 --- a/src/Fl_Native_File_Chooser_MAC.mm +++ b/src/Fl_Native_File_Chooser_MAC.mm @@ -417,9 +417,12 @@ int Fl_Quartz_Native_File_Chooser_Driver::get_saveas_basename(void) { const char *d = [[[[_panel URL] path] stringByDeletingLastPathComponent] UTF8String]; int l = (int)strlen(d) + 1; if (strcmp(d, "/") == 0) l = 1; - int lu = strlen(UNLIKELYPREFIX); - // Remove UNLIKELYPREFIX between directory and filename parts - if (memcmp(q+l, UNLIKELYPREFIX, lu) == 0) memmove(q + l, q + l + lu, strlen(q + l + lu) + 1); + int lu = (int)strlen(UNLIKELYPREFIX); + int ln = (int)strlen(q+l); + if (ln >= lu) { + // Remove UNLIKELYPREFIX between directory and filename parts + if (memcmp(q+l, UNLIKELYPREFIX, lu) == 0) memmove(q + l, q + l + lu, strlen(q + l + lu) + 1); + } } set_single_pathname( q ); free(q); -- cgit v1.2.3