From a5b0041b4a1f278eac800b4240bd3b1c5b7d2b99 Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Mon, 27 May 2024 07:46:58 -0700 Subject: [PATCH] Fixed SDL_strncmp() logic in portal dialog code Also removed redundant calls to SDL_strlen() Fixes https://github.com/libsdl-org/SDL/issues/9899 --- src/dialog/unix/SDL_portaldialog.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/dialog/unix/SDL_portaldialog.c b/src/dialog/unix/SDL_portaldialog.c index d0a52d59c8..8aa55bfde2 100644 --- a/src/dialog/unix/SDL_portaldialog.c +++ b/src/dialog/unix/SDL_portaldialog.c @@ -226,6 +226,8 @@ static DBusHandlerResult DBus_MessageFilter(DBusConnection *conn, DBusMessage *m while (dbus->message_iter_get_arg_type(&uri_entry) == DBUS_TYPE_STRING) { + const char *prefix = "file://"; + const int prefix_len = 7; const char *uri = NULL; if (current >= length - 1) { @@ -241,8 +243,8 @@ static DBusHandlerResult DBus_MessageFilter(DBusConnection *conn, DBusMessage *m /* https://flatpak.github.io/xdg-desktop-portal/docs/doc-org.freedesktop.portal.FileChooser.html */ /* Returned paths will always start with 'file://'; truncate it */ - if (SDL_strncmp(uri, "file://", SDL_strlen("file://"))) { - path[current] = uri + SDL_strlen("file://"); + if (SDL_strncmp(uri, prefix, prefix_len) == 0) { + path[current] = uri + prefix_len; } else if (SDL_strstr(uri, "://")) { SDL_SetError("Portal dialogs: Unsupported protocol: %s", uri); signal_data->callback(signal_data->userdata, NULL, -1);