diff options
| author | Matthias Melcher <github@matthiasm.com> | 2025-05-11 12:30:12 +0200 |
|---|---|---|
| committer | Matthias Melcher <github@matthiasm.com> | 2025-05-11 12:30:22 +0200 |
| commit | 74b0dc7d950c98ed38015a5f8f85e199637f7948 (patch) | |
| tree | 852c89d8ddebfb1c1138001de52179cbb655a85a | |
| parent | 95709ae0ad04046edba992723c74205d86284f3b (diff) | |
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.
| -rw-r--r-- | src/Fl_Native_File_Chooser_MAC.mm | 9 |
1 files changed, 6 insertions, 3 deletions
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); |
