Commit 216e50f4 authored by William Jon McCann's avatar William Jon McCann

Make getting extension more robust

Ensure the basename and extension have at least one char each.
parent a2b0ddd4
......@@ -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;
}
}
......
......@@ -543,7 +543,7 @@ parse_previous_duplicate_name (const char *name,
g_assert (name[0] != '\0');
*suffix = eel_filename_get_extension_offset (name + 1);
*suffix = eel_filename_get_extension_offset (name);
if (*suffix == NULL || (*suffix)[1] == '\0') {
/* no suffix */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment