In case anyone is idiotic enough to have files 20 dirs deep, I've
increased max path length to 5120. I'm not even sure if any of the audio
players support filenames that long.  I've also changed my unsafe
strcpy's to strncpy and added a null terminator just in case.  Here's
the patch


It's against my previous patch, obviously.  

--- ./fileselector.cpp  Fri Mar 29 22:05:53 2002
+++ ./fixed_fileselector.cpp    Fri Mar 29 21:53:58 2002
@@ -33,7 +33,7 @@
 #include "fileselector.h"
 #include "utility.h"
 
-char old_path[1024]="/\0";
+char old_path[5120]="/\0";
 
 FileSelector::FileSelector(const char *windowtitle)
 {
@@ -72,9 +72,10 @@
         current = readdir(dir);
         for(i=0;(current=readdir(dir))!=NULL;i++){
             if(current->d_type==DT_DIR){
-               char *temp_subdir = new char[1024];
-               strcpy(temp_subdir, subdirs);
+               char *temp_subdir = new char[5120];
+               strncpy(temp_subdir, subdirs,5120);
                strcat(temp_subdir,current->d_name);
+               temp_subdir[5120]='\0';
                returnpath = recursive_path(temp_subdir,returnpath,sub_rnum);
                delete [] temp_subdir;
            }
@@ -123,7 +124,8 @@
     path_temp = strdup(returnpath.c_str());
     raw_path =         gtk_entry_get_text(GTK_ENTRY(gfile->selection_entry));
     char *tempdir = strrchr(path_temp, '/');
-    strcpy(old_path,path_temp);
+    strncpy(old_path,path_temp,5120);
+    old_path[5120]='\0';
     if (!tempdir) {
         strcpy(path_temp, "./");
         path_temp = (char *)realloc(path_temp, strlen(path_temp) + 1);
@@ -150,8 +152,8 @@
        }
     } 
     else {
-       char *subdirs = new char[1024];
-       strcpy(subdirs,old_path);
+       char *subdirs = new char[5120];
+       strncpy(subdirs,old_path,5120);
        returnpath="";
        returnpath = recursive_path(subdirs, returnpath,&sub_rnum);
        delete [] subdirs;

Reply via email to