summaryrefslogtreecommitdiff
path: root/eel
diff options
context:
space:
mode:
authorWilliam Jon McCann <jmccann@redhat.com>2012-08-22 12:14:23 -0400
committerWilliam Jon McCann <jmccann@redhat.com>2012-08-22 14:22:12 -0400
commit216e50f40e816e7fcc0e1fdaf3a4c8e3e816b990 (patch)
tree0c743df36ba30601ab2ba2745e05e55e9e5d8a82 /eel
parenta2b0ddd45e19ec43d2fbf09204152c31aa0dc860 (diff)
downloadnautilus-216e50f40e816e7fcc0e1fdaf3a4c8e3e816b990.tar.gz
Make getting extension more robust
Ensure the basename and extension have at least one char each.
Diffstat (limited to 'eel')
-rw-r--r--eel/eel-vfs-extensions.c19
1 files changed, 15 insertions, 4 deletions
diff --git a/eel/eel-vfs-extensions.c b/eel/eel-vfs-extensions.c
index 75322533c..84a38a10c 100644
--- a/eel/eel-vfs-extensions.c
+++ b/eel/eel-vfs-extensions.c
@@ -106,20 +106,31 @@ char *
eel_filename_get_extension_offset (const char *filename)
{
char *end, *end2;
+ const char *start;
- end = strrchr (filename, '.');
+ if (filename == NULL || filename[0] == '\0') {
+ return NULL;
+ }
- if (end && end != filename) {
+ /* basename must have at least one char */
+ start = filename + 1;
+
+ end = strrchr (start, '.');
+ if (end == NULL || end[1] == '\0') {
+ return NULL;
+ }
+
+ if (end != start) {
if (strcmp (end, ".gz") == 0 ||
strcmp (end, ".bz2") == 0 ||
strcmp (end, ".sit") == 0 ||
strcmp (end, ".Z") == 0) {
end2 = end - 1;
- while (end2 > filename &&
+ while (end2 > start &&
*end2 != '.') {
end2--;
}
- if (end2 != filename) {
+ if (end2 != start) {
end = end2;
}
}