diff options
author | Corey Berla <corey@berla.me> | 2022-11-25 15:21:58 -0800 |
---|---|---|
committer | António Fernandes <antoniof@gnome.org> | 2022-12-23 11:10:25 -0500 |
commit | 0f478ed6ad79b3361fdcdc6c38e21c278616e19d (patch) | |
tree | 92800258914b2842becfdb43ffe6ec383f14d440 | |
parent | bfa47d36b92e4a28fa747c2852950e584fe83f0e (diff) | |
download | nautilus-0f478ed6ad79b3361fdcdc6c38e21c278616e19d.tar.gz |
file-operation: Return early when basename is NULL
Calling g_utf8_validate() on a NULL string crashes Nautilus. This
can occur if performing an operation on an invalid file. If
basename is NULL, there's nothing we would do anyways, so just
return early and prevent the crash.
There's a similar issue with get_unique_target_file(), but
if a bad uri was passed to this function it should fail much
earlier, so lets just add an assertion.
Fixes: https://gitlab.gnome.org/GNOME/nautilus/-/issues/2376
(cherry picked from commit e2969a9c29d0d171038fcb35d8baa5a7df372191)
-rw-r--r-- | src/nautilus-file-operations.c | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/src/nautilus-file-operations.c b/src/nautilus-file-operations.c index d358518b2..f39403b24 100644 --- a/src/nautilus-file-operations.c +++ b/src/nautilus-file-operations.c @@ -1021,6 +1021,11 @@ get_basename (GFile *file) if (name == NULL) { basename = g_file_get_basename (file); + if (basename == NULL) + { + return g_strdup (_("unknown")); + } + if (g_utf8_validate (basename, -1, NULL)) { name = basename; @@ -4383,6 +4388,7 @@ get_unique_target_file (GFile *src, if (dest == NULL) { basename = g_file_get_basename (src); + g_assert (basename == NULL); if (g_utf8_validate (basename, -1, NULL)) { |